From 3a246308dcd76f70a1b6c3e6b08f0d597b255dba Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 30 Jul 2016 00:29:03 -0300 Subject: Adding the basics graphics elements The base is done, bus under contruction --- Project/Bus.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Project/Bus.cpp (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp new file mode 100644 index 0000000..b598f40 --- /dev/null +++ b/Project/Bus.cpp @@ -0,0 +1,19 @@ +#include "Bus.h" + +Bus::Bus(wxPoint2DDouble position) : Element() +{ + m_width = 100.0; + m_height = 5.0; + SetPosition(position); +} +Bus::~Bus() {} + +void Bus::Draw(wxPoint2DDouble translation, double scale) const +{ + glColor4d(0.0, 0.0, 1.0, 1.0); + DrawRectangle(m_position, m_width, m_height); +} +bool Bus::Contains(wxPoint2DDouble position) const { return false; } +int Bus::PickboxContains(wxPoint2DDouble position) const { return 0; } +wxCursor Bus::GetBestPickboxCursor() const { return wxCURSOR_ARROW; } +void Bus::MovePickbox(wxPoint2DDouble position, int pickboxID) {} -- cgit From 78aac544e1e77f5405260797cee4b94d7a0dfe32 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 2 Aug 2016 17:34:42 -0300 Subject: Bus controllers under implementation Events handler removed --- Project/Bus.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 9 deletions(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index b598f40..c188beb 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -1,19 +1,95 @@ #include "Bus.h" -Bus::Bus(wxPoint2DDouble position) : Element() +Bus::Bus(wxPoint2DDouble position) : Element() { - m_width = 100.0; - m_height = 5.0; - SetPosition(position); + m_width = 100.0; + m_height = 5.0; + SetPosition(position); } Bus::~Bus() {} - void Bus::Draw(wxPoint2DDouble translation, double scale) const { - glColor4d(0.0, 0.0, 1.0, 1.0); - DrawRectangle(m_position, m_width, m_height); + // Draw selection (behind) + if(m_selected) { + // If the object is selected, the matrix is reset to remove scale effects applied to it, thus keeping the + // edges with fixed sizes for all zoom levels. + glPushMatrix(); + glLoadIdentity(); + // The matrix was reset, so we must use screen coordinates (WorldToScreen). + wxPoint2DDouble screenPt = WorldToScreen(translation, scale); + glTranslated(screenPt.m_x, screenPt.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-screenPt.m_x, -screenPt.m_y, 0.0); + + glColor4d(0.0, 0.5, 1.0, 0.5); + + wxPoint2DDouble pts[4] = {WorldToScreen(translation, scale, -(m_width / 2.0), -(m_height / 2.0)) - + wxPoint2DDouble(m_borderSize, m_borderSize), + WorldToScreen(translation, scale, -(m_width / 2.0), (m_height / 2.0)) - + wxPoint2DDouble(m_borderSize, -m_borderSize), + WorldToScreen(translation, scale, (m_width / 2.0), (m_height / 2.0)) - + wxPoint2DDouble(-m_borderSize, -m_borderSize), + WorldToScreen(translation, scale, (m_width / 2.0), -(m_height / 2.0)) - + wxPoint2DDouble(-m_borderSize, m_borderSize)}; + DrawRectangle(pts); + glPopMatrix(); + } + // Draw element (middle) + // Push the current matrix on stack. + glPushMatrix(); + // Rotate the matrix around the object position. + glTranslated(m_position.m_x, m_position.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-m_position.m_x, -m_position.m_y, 0.0); + + glColor4d(0.0, 0.3, 1.0, 1.0); + DrawRectangle(m_position, m_width, m_height); + // Pop the old matrix back. + glPopMatrix(); + + // Draw pickbox (above) + if(m_showPickbox) { + glPushMatrix(); + glLoadIdentity(); + + wxPoint2DDouble screenPt = WorldToScreen(translation, scale); + glTranslated(screenPt.m_x, screenPt.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-screenPt.m_x, -screenPt.m_y, 0.0); + + wxPoint2DDouble pbPosition[2] = {WorldToScreen(translation, scale, m_width / 2.0), + WorldToScreen(translation, scale, -m_width / 2.0)}; + DrawPickbox(pbPosition[0]); + DrawPickbox(pbPosition[1]); + + glPopMatrix(); + } +} +bool Bus::Contains(wxPoint2DDouble position) const +{ + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + return m_rect.Contains(ptR); } -bool Bus::Contains(wxPoint2DDouble position) const { return false; } int Bus::PickboxContains(wxPoint2DDouble position) const { return 0; } -wxCursor Bus::GetBestPickboxCursor() const { return wxCURSOR_ARROW; } +wxCursor Bus::GetBestPickboxCursor() const +{ + double angle = m_angle; + while(angle >= 157.5) angle -= 180.0; + + if(angle >= -22.5 && angle < 22.5) + return wxCursor(wxCURSOR_SIZEWE); + else if(angle >= 22.5 && angle < 67.5) + return wxCursor(wxCURSOR_SIZENWSE); + else if(angle >= 67.5 && angle < 112.5) + return wxCursor(wxCURSOR_SIZENS); + else if(angle >= 112.5 && angle < 157.5) + return wxCursor(wxCURSOR_SIZENESW); + + return wxCursor(wxCURSOR_ARROW); +} void Bus::MovePickbox(wxPoint2DDouble position, int pickboxID) {} +void Bus::Rotate() +{ + m_angle += 45.0; + if(m_angle >= 360.0) m_angle = 0.0; +} -- cgit From 0b720e578e0e91262e04651ce81cd2e7f6828967 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Wed, 3 Aug 2016 00:15:54 -0300 Subject: More controllers add to bus Next step: move elements --- Project/Bus.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index c188beb..fe12c5b 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -6,10 +6,12 @@ Bus::Bus(wxPoint2DDouble position) : Element() m_height = 5.0; SetPosition(position); } + Bus::~Bus() {} + void Bus::Draw(wxPoint2DDouble translation, double scale) const { - // Draw selection (behind) + // Draw selection (layer 1) if(m_selected) { // If the object is selected, the matrix is reset to remove scale effects applied to it, thus keeping the // edges with fixed sizes for all zoom levels. @@ -34,7 +36,7 @@ void Bus::Draw(wxPoint2DDouble translation, double scale) const DrawRectangle(pts); glPopMatrix(); } - // Draw element (middle) + // Draw element (layer 2) // Push the current matrix on stack. glPushMatrix(); // Rotate the matrix around the object position. @@ -47,7 +49,7 @@ void Bus::Draw(wxPoint2DDouble translation, double scale) const // Pop the old matrix back. glPopMatrix(); - // Draw pickbox (above) + // Draw pickbox (layer 3) if(m_showPickbox) { glPushMatrix(); glLoadIdentity(); @@ -65,12 +67,35 @@ void Bus::Draw(wxPoint2DDouble translation, double scale) const glPopMatrix(); } } + bool Bus::Contains(wxPoint2DDouble position) const { wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); return m_rect.Contains(ptR); } -int Bus::PickboxContains(wxPoint2DDouble position) const { return 0; } + +bool Bus::PickboxContains(wxPoint2DDouble position) +{ + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + + wxPoint2DDouble center(m_position.m_x + m_width / 2.0, m_position.m_y); + wxRect2DDouble rectRight(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0); + + center = wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y); + wxRect2DDouble rectLeft(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0); + + if(rectRight.Contains(ptR)){ + m_activePickboxID = ID_PB_RIGHT; + return true; + } + else if(rectLeft.Contains(ptR)){ + m_activePickboxID = ID_PB_LEFT; + return true; + } + + return false; +} + wxCursor Bus::GetBestPickboxCursor() const { double angle = m_angle; @@ -87,7 +112,32 @@ wxCursor Bus::GetBestPickboxCursor() const return wxCursor(wxCURSOR_ARROW); } -void Bus::MovePickbox(wxPoint2DDouble position, int pickboxID) {} + +void Bus::MovePickbox(wxPoint2DDouble position) +{ + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + + double dx = 0.0; + if(m_activePickboxID == ID_PB_RIGHT) + dx = ptR.m_x - m_position.m_x - m_width / 2.0; + else if(m_activePickboxID == ID_PB_LEFT) + dx = m_position.m_x - m_width / 2.0 - ptR.m_x ; + + if(m_width + dx < 20.0) return; + + if(m_activePickboxID == ID_PB_RIGHT) { + m_position.m_x += (dx / 2.0) * std::cos(wxDegToRad(m_angle)); + m_position.m_y += (dx / 2.0) * std::sin(wxDegToRad(m_angle)); + } + else if(m_activePickboxID == ID_PB_LEFT) { + m_position.m_x -= (dx / 2.0) * std::cos(wxDegToRad(m_angle)); + m_position.m_y -= (dx / 2.0) * std::sin(wxDegToRad(m_angle)); + } + m_width += dx; + + SetPosition(m_position); +} + void Bus::Rotate() { m_angle += 45.0; -- cgit From 46c9d3fe586fb5c8ac75384b62a79971f96a5b88 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 3 Aug 2016 17:43:25 -0300 Subject: Bus implemented, selection not working Selection to move fail --- Project/Bus.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index fe12c5b..064f481 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -1,5 +1,6 @@ #include "Bus.h" +Bus::Bus() : Element() {} Bus::Bus(wxPoint2DDouble position) : Element() { m_width = 100.0; @@ -8,7 +9,6 @@ Bus::Bus(wxPoint2DDouble position) : Element() } Bus::~Bus() {} - void Bus::Draw(wxPoint2DDouble translation, double scale) const { // Draw selection (layer 1) @@ -76,24 +76,27 @@ bool Bus::Contains(wxPoint2DDouble position) const bool Bus::PickboxContains(wxPoint2DDouble position) { - wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + m_activePickboxID = ID_PB_NONE; + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + wxPoint2DDouble center(m_position.m_x + m_width / 2.0, m_position.m_y); wxRect2DDouble rectRight(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0); center = wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y); wxRect2DDouble rectLeft(center.m_x - 5.0, center.m_y - 5.0, 10.0, 10.0); - - if(rectRight.Contains(ptR)){ - m_activePickboxID = ID_PB_RIGHT; - return true; + + if(rectRight.Contains(ptR)) { + m_activePickboxID = ID_PB_RIGHT; + return true; } - else if(rectLeft.Contains(ptR)){ - m_activePickboxID = ID_PB_LEFT; - return true; + if(rectLeft.Contains(ptR)) + { + m_activePickboxID = ID_PB_LEFT; + return true; } - return false; + return false; } wxCursor Bus::GetBestPickboxCursor() const @@ -115,23 +118,26 @@ wxCursor Bus::GetBestPickboxCursor() const void Bus::MovePickbox(wxPoint2DDouble position) { - wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + if(m_activePickboxID == ID_PB_NONE) return; + + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); double dx = 0.0; if(m_activePickboxID == ID_PB_RIGHT) dx = ptR.m_x - m_position.m_x - m_width / 2.0; else if(m_activePickboxID == ID_PB_LEFT) - dx = m_position.m_x - m_width / 2.0 - ptR.m_x ; + dx = m_position.m_x - m_width / 2.0 - ptR.m_x; if(m_width + dx < 20.0) return; - - if(m_activePickboxID == ID_PB_RIGHT) { - m_position.m_x += (dx / 2.0) * std::cos(wxDegToRad(m_angle)); - m_position.m_y += (dx / 2.0) * std::sin(wxDegToRad(m_angle)); + + if(m_activePickboxID == ID_PB_RIGHT) { + m_position.m_x += (dx / 2.0) * std::cos(wxDegToRad(m_angle)); + m_position.m_y += (dx / 2.0) * std::sin(wxDegToRad(m_angle)); } - else if(m_activePickboxID == ID_PB_LEFT) { - m_position.m_x -= (dx / 2.0) * std::cos(wxDegToRad(m_angle)); - m_position.m_y -= (dx / 2.0) * std::sin(wxDegToRad(m_angle)); + else if(m_activePickboxID == ID_PB_LEFT) + { + m_position.m_x -= (dx / 2.0) * std::cos(wxDegToRad(m_angle)); + m_position.m_y -= (dx / 2.0) * std::sin(wxDegToRad(m_angle)); } m_width += dx; -- cgit From 139b076149594e6cf508aea269b061aa8b428d9c Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sun, 7 Aug 2016 21:36:40 -0300 Subject: Some minor fixes --- Project/Bus.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index 064f481..923d947 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -74,10 +74,15 @@ bool Bus::Contains(wxPoint2DDouble position) const return m_rect.Contains(ptR); } +bool Bus::Intersects(wxRect2DDouble rect) const +{ + return rect.Intersects(m_rect); +} + bool Bus::PickboxContains(wxPoint2DDouble position) { - m_activePickboxID = ID_PB_NONE; - + m_activePickboxID = ID_PB_NONE; + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); wxPoint2DDouble center(m_position.m_x + m_width / 2.0, m_position.m_y); @@ -90,12 +95,11 @@ bool Bus::PickboxContains(wxPoint2DDouble position) m_activePickboxID = ID_PB_RIGHT; return true; } - if(rectLeft.Contains(ptR)) - { + if(rectLeft.Contains(ptR)) { m_activePickboxID = ID_PB_LEFT; return true; } - + return false; } @@ -118,8 +122,8 @@ wxCursor Bus::GetBestPickboxCursor() const void Bus::MovePickbox(wxPoint2DDouble position) { - if(m_activePickboxID == ID_PB_NONE) return; - + if(m_activePickboxID == ID_PB_NONE) return; + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); double dx = 0.0; -- cgit From b5324f48c855b0c82ccf6da7d5a008fe5cf1c17e Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 8 Aug 2016 17:01:53 -0300 Subject: Start Power Line implementation gogogogo --- Project/Bus.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index 923d947..a7ebf59 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -9,6 +9,7 @@ Bus::Bus(wxPoint2DDouble position) : Element() } Bus::~Bus() {} + void Bus::Draw(wxPoint2DDouble translation, double scale) const { // Draw selection (layer 1) @@ -74,11 +75,7 @@ bool Bus::Contains(wxPoint2DDouble position) const return m_rect.Contains(ptR); } -bool Bus::Intersects(wxRect2DDouble rect) const -{ - return rect.Intersects(m_rect); -} - +bool Bus::Intersects(wxRect2DDouble rect) const { return rect.Intersects(m_rect); } bool Bus::PickboxContains(wxPoint2DDouble position) { m_activePickboxID = ID_PB_NONE; -- cgit From 05525745c0b0d189484da3c45f95356d7558e2cf Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 18 Aug 2016 19:10:04 -0300 Subject: Line improvements, context menu implemented Line still under construction, contex menu base implemented --- Project/Bus.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Project/Bus.cpp') diff --git a/Project/Bus.cpp b/Project/Bus.cpp index a7ebf59..a578e1b 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -147,6 +147,13 @@ void Bus::MovePickbox(wxPoint2DDouble position) void Bus::Rotate() { - m_angle += 45.0; + m_angle += m_rotationAngle; if(m_angle >= 360.0) m_angle = 0.0; } + +bool Bus::GetContextMenu(wxMenu& menu) +{ + menu.Append(ID_EDIT_BUS, _("Edit bus")); + menu.Append(ID_ROTATE, _("Rotate")); + return true; +} -- cgit