diff options
Diffstat (limited to 'Project')
-rw-r--r-- | Project/Bus.cpp | 8 | ||||
-rw-r--r-- | Project/Element.cpp | 105 | ||||
-rw-r--r-- | Project/Element.h | 3 | ||||
-rw-r--r-- | Project/Project.mk | 7 | ||||
-rw-r--r-- | Project/Release/Bus.cpp.o | bin | 30860 -> 29614 bytes | |||
-rw-r--r-- | Project/Release/Element.cpp.o | bin | 22418 -> 24770 bytes | |||
-rw-r--r-- | Project/Release/Line.cpp.o | bin | 40746 -> 40924 bytes | |||
-rw-r--r-- | Project/Release/Line.cpp.o.d | 152 | ||||
-rw-r--r-- | Project/Release/PSP-UFU.exe | bin | 3300405 -> 3310428 bytes | |||
-rw-r--r-- | Project/Release/Transformer.cpp.o | bin | 25730 -> 36539 bytes | |||
-rw-r--r-- | Project/Release/Workspace.cpp.o | bin | 118267 -> 118181 bytes | |||
-rw-r--r-- | Project/Transformer.cpp | 329 | ||||
-rw-r--r-- | Project/Transformer.h | 9 | ||||
-rw-r--r-- | Project/Workspace.cpp | 2 |
14 files changed, 481 insertions, 134 deletions
diff --git a/Project/Bus.cpp b/Project/Bus.cpp index 9484328..9f38da0 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -36,7 +36,7 @@ void Bus::Draw(wxPoint2DDouble translation, double scale) const DrawRectangle(pts); glPopMatrix(); } - // Draw element (layer 2) + // Draw bus (layer 2) // Push the current matrix on stack. glPushMatrix(); // Rotate the matrix around the object position. @@ -77,8 +77,10 @@ bool Bus::Contains(wxPoint2DDouble position) const bool Bus::Intersects(wxRect2DDouble rect) const { if(m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect); + + return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0); - wxPoint2DDouble m_rectCorners[4] = {m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(), + /*wxPoint2DDouble m_rectCorners[4] = {m_rect.GetLeftTop(), m_rect.GetLeftBottom(), m_rect.GetRightBottom(), m_rect.GetRightTop()}; wxPoint2DDouble rectCorners[4] = {rect.GetLeftTop(), rect.GetLeftBottom(), rect.GetRightBottom(), rect.GetRightTop()}; @@ -144,7 +146,7 @@ bool Bus::Intersects(wxRect2DDouble rect) const } return true; - // return rect.Intersects(m_rect); + // return rect.Intersects(m_rect);*/ } bool Bus::PickboxContains(wxPoint2DDouble position) { diff --git a/Project/Element.cpp b/Project/Element.cpp index 7f0e211..d00837a 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -103,8 +103,107 @@ wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale scale; } -wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble position, wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const +wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble position, + wxPoint2DDouble translation, + double scale, + double offsetX, + double offsetY) const { - return wxPoint2DDouble(position.m_x + offsetX + translation.m_x, position.m_y + offsetY + translation.m_y) * - scale; + return wxPoint2DDouble(position.m_x + offsetX + translation.m_x, position.m_y + offsetY + translation.m_y) * scale; +} + +void Element::DrawPoint(wxPoint2DDouble position, double size) const +{ + glPointSize(size); + glBegin(GL_POINTS); + glVertex2d(position.m_x, position.m_y); + glEnd(); +} + +bool Element::RotatedRectanglesIntersects(wxRect2DDouble rect1, + wxRect2DDouble rect2, + double angle1, + double angle2) const +{ + wxPoint2DDouble rect1Corners[4] = {rect1.GetLeftTop(), rect1.GetLeftBottom(), rect1.GetRightBottom(), + rect1.GetRightTop()}; + wxPoint2DDouble rect2Corners[4] = {rect2.GetLeftTop(), rect2.GetLeftBottom(), rect2.GetRightBottom(), + rect2.GetRightTop()}; + wxPoint2DDouble rect1Center(rect1.m_x + rect1.m_width / 2.0, rect1.m_y + rect1.m_height / 2.0); + wxPoint2DDouble rect2Center(rect2.m_x + rect2.m_width / 2.0, rect2.m_y + rect2.m_height / 2.0); + + // Rotate the corners. + double radAngle1 = wxDegToRad(angle1); + double radAngle2 = wxDegToRad(angle2); + + for(int i = 0; i < 4; i++) { + rect1Corners[i] = + wxPoint2DDouble(std::cos(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) - + std::sin(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_x, + std::sin(radAngle1) * (rect1Corners[i].m_x - rect1Center.m_x) + + std::cos(radAngle1) * (rect1Corners[i].m_y - rect1Center.m_y) + rect1Center.m_y); + + rect2Corners[i] = + wxPoint2DDouble(std::cos(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) - + std::sin(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_x, + std::sin(radAngle2) * (rect2Corners[i].m_x - rect2Center.m_x) + + std::cos(radAngle2) * (rect2Corners[i].m_y - rect2Center.m_y) + rect2Center.m_y); + } + + //[Ref] http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604 + + // Find the rectangles axis to project + wxPoint2DDouble axis[4] = {rect1Corners[3] - rect1Corners[0], rect1Corners[3] - rect1Corners[2], + rect2Corners[3] - rect2Corners[0], rect2Corners[3] - rect2Corners[2]}; + + // Calculate the projected points to each axis + wxPoint2DDouble rect1ProjPts[4][4]; // [axis][corner] + wxPoint2DDouble rect2ProjPts[4][4]; // [axis][corner] + for(int i = 0; i < 4; i++) { + double den = axis[i].m_x * axis[i].m_x + axis[i].m_y * axis[i].m_y; + for(int j = 0; j < 4; j++) { + double m_rectProj = (rect1Corners[j].m_x * axis[i].m_x + rect1Corners[j].m_y * axis[i].m_y) / den; + double rectProj = (rect2Corners[j].m_x * axis[i].m_x + rect2Corners[j].m_y * axis[i].m_y) / den; + + rect1ProjPts[i][j] = wxPoint2DDouble(m_rectProj * axis[i].m_x, m_rectProj * axis[i].m_y); + rect2ProjPts[i][j] = wxPoint2DDouble(rectProj * axis[i].m_x, rectProj * axis[i].m_y); + } + } + + // Calculate the scalar value to identify the max and min values on projections + double rect1Scalar[4][4]; //[axis][corner] + double rect2Scalar[4][4]; //[axis][corner] + for(int i = 0; i < 4; i++) { + for(int j = 0; j < 4; j++) { + rect1Scalar[i][j] = rect1ProjPts[i][j].m_x * axis[i].m_x + rect1ProjPts[i][j].m_y * axis[i].m_y; + rect2Scalar[i][j] = rect2ProjPts[i][j].m_x * axis[i].m_x + rect2ProjPts[i][j].m_y * axis[i].m_y; + } + } + // Identify the max and min scalar values + double rect1Min[4]; + double rect1Max[4]; + double rect2Min[4]; + double rect2Max[4]; + + for(int i = 0; i < 4; i++) { + rect1Max[i] = rect1Scalar[i][0]; + rect2Max[i] = rect2Scalar[i][0]; + rect1Min[i] = rect1Scalar[i][0]; + rect2Min[i] = rect2Scalar[i][0]; + + for(int j = 1; j < 4; j++) { + if(rect1Max[i] < rect1Scalar[i][j]) rect1Max[i] = rect1Scalar[i][j]; + if(rect2Max[i] < rect2Scalar[i][j]) rect2Max[i] = rect2Scalar[i][j]; + + if(rect1Min[i] > rect1Scalar[i][j]) rect1Min[i] = rect1Scalar[i][j]; + if(rect2Min[i] > rect2Scalar[i][j]) rect2Min[i] = rect2Scalar[i][j]; + } + } + + // Check if any segment don't overlap + for(int i = 0; i < 4; i++) { + if(!(rect2Min[i] <= rect1Max[i] && rect2Max[i] >= rect1Min[i])) return false; + } + + return true; } diff --git a/Project/Element.h b/Project/Element.h index e4f2116..5b7c09d 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -21,6 +21,7 @@ enum ContextMenuID { ID_EDIT_BUS = 0, ID_EDIT_LINE, + ID_EDIT_TRANSFORMER, ID_LINE_ADD_NODE, ID_LINE_REMOVE_NODE, @@ -88,9 +89,11 @@ class Element double scale, double offsetX = 0.0, double offsetY = 0.0) const; + virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) 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 DrawPoint(wxPoint2DDouble position, double size) 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; diff --git a/Project/Project.mk b/Project/Project.mk index c2f3fd1..4824e5e 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,8 +13,8 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=30/08/2016 -CodeLitePath :="C:/Program Files/CodeLite" +Date :=31/08/2016 +CodeLitePath :="C:/Program Files (x86)/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC ObjectSuffix :=.o @@ -61,7 +61,8 @@ AS := C:/TDM-GCC-64/bin/as.exe ## ## User defined environment variables ## -CodeLiteDir:=C:\Program Files\CodeLite +CodeLiteDir:=C:\Program Files (x86)\CodeLite +UNIT_TEST_PP_SRC_DIR:=C:\UnitTest++-1.3 WXWIN:=C:\wxWidgets-3.1.0 WXCFG:=gcc_dll\mswu Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/win_resources.rc$(ObjectSuffix) $(IntermediateDirectory)/Element.cpp$(ObjectSuffix) $(IntermediateDirectory)/Bus.cpp$(ObjectSuffix) $(IntermediateDirectory)/Line.cpp$(ObjectSuffix) $(IntermediateDirectory)/Transformer.cpp$(ObjectSuffix) $(IntermediateDirectory)/ArtMetro.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrame.cpp$(ObjectSuffix) $(IntermediateDirectory)/Workspace.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) \ diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o Binary files differindex 281584b..f546ace 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 1fb0803..e2f3a38 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 8bb6364..c097a60 100644 --- a/Project/Release/Line.cpp.o +++ b/Project/Release/Line.cpp.o diff --git a/Project/Release/Line.cpp.o.d b/Project/Release/Line.cpp.o.d index 040ae16..119d78a 100644 --- a/Project/Release/Line.cpp.o.d +++ b/Project/Release/Line.cpp.o.d @@ -1,5 +1,5 @@ -Release/Line.cpp.o: Line.cpp Line.h \ - C:/wxWidgets-3.1.0/include/wx/msgdlg.h \ +Release/Line.cpp.o: Line.cpp Line.h Element.h \ + C:/wxWidgets-3.1.0/include/wx/geometry.h \ C:/wxWidgets-3.1.0/include/wx/defs.h \ C:/wxWidgets-3.1.0/include/wx/platform.h \ C:/wxWidgets-3.1.0/include/wx/compiler.h \ @@ -16,11 +16,7 @@ Release/Line.cpp.o: Line.cpp Line.h \ C:/wxWidgets-3.1.0/include/wx/windowid.h \ C:/wxWidgets-3.1.0/include/wx/msw/winundef.h \ C:/wxWidgets-3.1.0/include/wx/features.h \ - C:/wxWidgets-3.1.0/include/wx/dialog.h \ - C:/wxWidgets-3.1.0/include/wx/toplevel.h \ - C:/wxWidgets-3.1.0/include/wx/nonownedwnd.h \ - C:/wxWidgets-3.1.0/include/wx/window.h \ - C:/wxWidgets-3.1.0/include/wx/event.h \ + C:/wxWidgets-3.1.0/include/wx/utils.h \ C:/wxWidgets-3.1.0/include/wx/object.h \ C:/wxWidgets-3.1.0/include/wx/memory.h \ C:/wxWidgets-3.1.0/include/wx/string.h \ @@ -39,10 +35,6 @@ Release/Line.cpp.o: Line.cpp Line.h \ C:/wxWidgets-3.1.0/include/wx/xti.h C:/wxWidgets-3.1.0/include/wx/rtti.h \ C:/wxWidgets-3.1.0/include/wx/flags.h \ C:/wxWidgets-3.1.0/include/wx/xti2.h \ - C:/wxWidgets-3.1.0/include/wx/clntdata.h \ - C:/wxWidgets-3.1.0/include/wx/hashmap.h \ - C:/wxWidgets-3.1.0/include/wx/wxcrt.h \ - C:/wxWidgets-3.1.0/include/wx/gdicmn.h \ C:/wxWidgets-3.1.0/include/wx/list.h \ C:/wxWidgets-3.1.0/include/wx/vector.h \ C:/wxWidgets-3.1.0/include/wx/scopeguard.h \ @@ -50,20 +42,26 @@ Release/Line.cpp.o: Line.cpp Line.h \ C:/wxWidgets-3.1.0/include/wx/meta/movable.h \ C:/wxWidgets-3.1.0/include/wx/meta/pod.h \ C:/wxWidgets-3.1.0/include/wx/meta/if.h \ - C:/wxWidgets-3.1.0/include/wx/math.h \ - C:/wxWidgets-3.1.0/include/wx/cursor.h \ - C:/wxWidgets-3.1.0/include/wx/gdiobj.h \ - C:/wxWidgets-3.1.0/include/wx/msw/gdiimage.h \ - C:/wxWidgets-3.1.0/include/wx/msw/cursor.h \ - C:/wxWidgets-3.1.0/include/wx/utils.h \ C:/wxWidgets-3.1.0/include/wx/filefn.h \ C:/wxWidgets-3.1.0/include/wx/arrstr.h \ + C:/wxWidgets-3.1.0/include/wx/hashmap.h \ + C:/wxWidgets-3.1.0/include/wx/wxcrt.h \ C:/wxWidgets-3.1.0/include/wx/versioninfo.h \ C:/wxWidgets-3.1.0/include/wx/meta/implicitconversion.h \ + C:/wxWidgets-3.1.0/include/wx/gdicmn.h \ + C:/wxWidgets-3.1.0/include/wx/math.h \ C:/wxWidgets-3.1.0/include/wx/mousestate.h \ C:/wxWidgets-3.1.0/include/wx/kbdstate.h \ C:/wxWidgets-3.1.0/include/wx/longlong.h \ C:/wxWidgets-3.1.0/include/wx/platinfo.h \ + C:/wxWidgets-3.1.0/include/wx/cursor.h \ + C:/wxWidgets-3.1.0/include/wx/gdiobj.h \ + C:/wxWidgets-3.1.0/include/wx/msw/gdiimage.h \ + C:/wxWidgets-3.1.0/include/wx/msw/cursor.h \ + C:/wxWidgets-3.1.0/include/wx/menu.h \ + C:/wxWidgets-3.1.0/include/wx/window.h \ + C:/wxWidgets-3.1.0/include/wx/event.h \ + C:/wxWidgets-3.1.0/include/wx/clntdata.h \ C:/wxWidgets-3.1.0/include/wx/dynarray.h \ C:/wxWidgets-3.1.0/include/wx/thread.h \ C:/wxWidgets-3.1.0/include/wx/tracker.h \ @@ -92,26 +90,6 @@ Release/Line.cpp.o: Line.cpp Line.h \ C:/wxWidgets-3.1.0/include/wx/msw/accel.h \ C:/wxWidgets-3.1.0/include/wx/msw/window.h \ C:/wxWidgets-3.1.0/include/wx/settings.h \ - C:/wxWidgets-3.1.0/include/wx/msw/nonownedwnd.h \ - C:/wxWidgets-3.1.0/include/wx/iconbndl.h \ - C:/wxWidgets-3.1.0/include/wx/icon.h \ - C:/wxWidgets-3.1.0/include/wx/iconloc.h \ - C:/wxWidgets-3.1.0/include/wx/msw/icon.h \ - C:/wxWidgets-3.1.0/include/wx/weakref.h \ - C:/wxWidgets-3.1.0/include/wx/meta/int2type.h \ - C:/wxWidgets-3.1.0/include/wx/msw/toplevel.h \ - C:/wxWidgets-3.1.0/include/wx/containr.h \ - C:/wxWidgets-3.1.0/include/wx/sharedptr.h \ - C:/wxWidgets-3.1.0/include/wx/atomic.h \ - C:/wxWidgets-3.1.0/include/wx/msw/wrapwin.h \ - C:/wxWidgets-3.1.0/include/wx/msw/dialog.h \ - C:/wxWidgets-3.1.0/include/wx/panel.h \ - C:/wxWidgets-3.1.0/include/wx/msw/panel.h \ - C:/wxWidgets-3.1.0/include/wx/stockitem.h \ - C:/wxWidgets-3.1.0/include/wx/generic/msgdlgg.h \ - C:/wxWidgets-3.1.0/include/wx/msw/msgdlg.h Element.h \ - C:/wxWidgets-3.1.0/include/wx/geometry.h \ - C:/wxWidgets-3.1.0/include/wx/menu.h \ C:/wxWidgets-3.1.0/include/wx/menuitem.h \ C:/wxWidgets-3.1.0/include/wx/msw/menuitem.h \ C:/wxWidgets-3.1.0/include/wx/bitmap.h \ @@ -134,7 +112,9 @@ Release/Line.cpp.o: Line.cpp Line.h \ Line.h: -C:/wxWidgets-3.1.0/include/wx/msgdlg.h: +Element.h: + +C:/wxWidgets-3.1.0/include/wx/geometry.h: C:/wxWidgets-3.1.0/include/wx/defs.h: @@ -168,15 +148,7 @@ C:/wxWidgets-3.1.0/include/wx/msw/winundef.h: C:/wxWidgets-3.1.0/include/wx/features.h: -C:/wxWidgets-3.1.0/include/wx/dialog.h: - -C:/wxWidgets-3.1.0/include/wx/toplevel.h: - -C:/wxWidgets-3.1.0/include/wx/nonownedwnd.h: - -C:/wxWidgets-3.1.0/include/wx/window.h: - -C:/wxWidgets-3.1.0/include/wx/event.h: +C:/wxWidgets-3.1.0/include/wx/utils.h: C:/wxWidgets-3.1.0/include/wx/object.h: @@ -216,14 +188,6 @@ C:/wxWidgets-3.1.0/include/wx/flags.h: C:/wxWidgets-3.1.0/include/wx/xti2.h: -C:/wxWidgets-3.1.0/include/wx/clntdata.h: - -C:/wxWidgets-3.1.0/include/wx/hashmap.h: - -C:/wxWidgets-3.1.0/include/wx/wxcrt.h: - -C:/wxWidgets-3.1.0/include/wx/gdicmn.h: - C:/wxWidgets-3.1.0/include/wx/list.h: C:/wxWidgets-3.1.0/include/wx/vector.h: @@ -238,26 +202,22 @@ C:/wxWidgets-3.1.0/include/wx/meta/pod.h: C:/wxWidgets-3.1.0/include/wx/meta/if.h: -C:/wxWidgets-3.1.0/include/wx/math.h: - -C:/wxWidgets-3.1.0/include/wx/cursor.h: - -C:/wxWidgets-3.1.0/include/wx/gdiobj.h: - -C:/wxWidgets-3.1.0/include/wx/msw/gdiimage.h: - -C:/wxWidgets-3.1.0/include/wx/msw/cursor.h: - -C:/wxWidgets-3.1.0/include/wx/utils.h: - C:/wxWidgets-3.1.0/include/wx/filefn.h: C:/wxWidgets-3.1.0/include/wx/arrstr.h: +C:/wxWidgets-3.1.0/include/wx/hashmap.h: + +C:/wxWidgets-3.1.0/include/wx/wxcrt.h: + C:/wxWidgets-3.1.0/include/wx/versioninfo.h: C:/wxWidgets-3.1.0/include/wx/meta/implicitconversion.h: +C:/wxWidgets-3.1.0/include/wx/gdicmn.h: + +C:/wxWidgets-3.1.0/include/wx/math.h: + C:/wxWidgets-3.1.0/include/wx/mousestate.h: C:/wxWidgets-3.1.0/include/wx/kbdstate.h: @@ -266,6 +226,22 @@ C:/wxWidgets-3.1.0/include/wx/longlong.h: C:/wxWidgets-3.1.0/include/wx/platinfo.h: +C:/wxWidgets-3.1.0/include/wx/cursor.h: + +C:/wxWidgets-3.1.0/include/wx/gdiobj.h: + +C:/wxWidgets-3.1.0/include/wx/msw/gdiimage.h: + +C:/wxWidgets-3.1.0/include/wx/msw/cursor.h: + +C:/wxWidgets-3.1.0/include/wx/menu.h: + +C:/wxWidgets-3.1.0/include/wx/window.h: + +C:/wxWidgets-3.1.0/include/wx/event.h: + +C:/wxWidgets-3.1.0/include/wx/clntdata.h: + C:/wxWidgets-3.1.0/include/wx/dynarray.h: C:/wxWidgets-3.1.0/include/wx/thread.h: @@ -322,48 +298,6 @@ C:/wxWidgets-3.1.0/include/wx/msw/window.h: C:/wxWidgets-3.1.0/include/wx/settings.h: -C:/wxWidgets-3.1.0/include/wx/msw/nonownedwnd.h: - -C:/wxWidgets-3.1.0/include/wx/iconbndl.h: - -C:/wxWidgets-3.1.0/include/wx/icon.h: - -C:/wxWidgets-3.1.0/include/wx/iconloc.h: - -C:/wxWidgets-3.1.0/include/wx/msw/icon.h: - -C:/wxWidgets-3.1.0/include/wx/weakref.h: - -C:/wxWidgets-3.1.0/include/wx/meta/int2type.h: - -C:/wxWidgets-3.1.0/include/wx/msw/toplevel.h: - -C:/wxWidgets-3.1.0/include/wx/containr.h: - -C:/wxWidgets-3.1.0/include/wx/sharedptr.h: - -C:/wxWidgets-3.1.0/include/wx/atomic.h: - -C:/wxWidgets-3.1.0/include/wx/msw/wrapwin.h: - -C:/wxWidgets-3.1.0/include/wx/msw/dialog.h: - -C:/wxWidgets-3.1.0/include/wx/panel.h: - -C:/wxWidgets-3.1.0/include/wx/msw/panel.h: - -C:/wxWidgets-3.1.0/include/wx/stockitem.h: - -C:/wxWidgets-3.1.0/include/wx/generic/msgdlgg.h: - -C:/wxWidgets-3.1.0/include/wx/msw/msgdlg.h: - -Element.h: - -C:/wxWidgets-3.1.0/include/wx/geometry.h: - -C:/wxWidgets-3.1.0/include/wx/menu.h: - C:/wxWidgets-3.1.0/include/wx/menuitem.h: C:/wxWidgets-3.1.0/include/wx/msw/menuitem.h: diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe Binary files differindex 3f9e388..a445fed 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o Binary files differindex e57ba06..21ea73a 100644 --- a/Project/Release/Transformer.cpp.o +++ b/Project/Release/Transformer.cpp.o diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o Binary files differindex e642dd3..2004be3 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 30413d5..3cd0b6e 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -26,6 +26,19 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back. + // Get the average between the two bus points. + m_position = wxPoint2DDouble((m_pointList[0].m_x + parentPt.m_x) / 2.0, + (m_pointList[0].m_y + parentPt.m_y) / 2.0); + // Set the transformer rectangle. + m_width = 70.0; + m_height = 40.0; + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, + m_height); + // Set the "side" points. + m_pointList.push_back(wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(-10, m_height / 2.0))); + m_pointList.push_back( + wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(m_width + 10, m_height / 2.0))); + // Set first switch point. wxPoint2DDouble secondPoint = parentPt; if(m_pointList.size() > 2) { @@ -38,26 +51,314 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) m_pointList.push_back(parentPt); // Last point. m_inserted = true; + return true; + } + } + return false; +} - // The average between the two bus points. - m_position = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[m_pointList.size() - 1].m_x) / 2.0, - (m_pointList[0].m_y + m_pointList[m_pointList.size() - 1].m_y) / 2.0); +bool Transformer::Contains(wxPoint2DDouble position) const +{ + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + return m_rect.Contains(ptR); +} - m_width = 80.0; - m_height = 50.0; - m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, - m_height); +void Transformer::Draw(wxPoint2DDouble translation, double scale) const +{ + if(m_inserted) { + // Draw selection (layer 1). + if(m_selected) { + // Push the current matrix on stack. + glLineWidth(1.5 + m_borderSize * 2.0); + glColor4d(0.0, 0.5, 1.0, 0.5); + DrawLine(m_pointList); + 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); - return true; + // glColor4d(0.0, 0.5, 1.0, 0.5); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, + 20, GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, + 20, GL_POLYGON); + + glPopMatrix(); + + // Draw nodes selection. + if(m_pointList.size() > 0) { + DrawCircle(m_pointList[0], 5.0 + m_borderSize, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize, 10, GL_POLYGON); + } + } + } + + // Draw transformer (layer 2). + // Transformer line + glLineWidth(1.5); + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawLine(m_pointList); + + // Draw nodes. + if(m_pointList.size() > 0) { + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); + } } + + // 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(1.0, 1.0, 1.0, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, GL_POLYGON); + + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20); + + DrawPoint(m_rect.GetPosition(), 8.0 * scale); + + glPopMatrix(); } +} + +bool Transformer::Intersects(wxRect2DDouble rect) const +{ + if(m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect); + return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0); +} + +void Transformer::Rotate() +{ + m_angle += m_rotationAngle; + if(m_angle >= 360.0) m_angle = 0.0; + + // Rotate all the points, except the switches and buses points. + for(int i = 2; i < (int)m_pointList.size() - 2; i++) { + m_pointList[i] = RotateAtPosition(m_pointList[i], m_rotationAngle); + } +} + +void Transformer::UpdateSwitchesPosition() +{ + if(m_parentList[0]) { + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); + } + else + { + m_pointList[1] = m_pointList[0]; + } + if(m_parentList[1]) { + m_pointList[m_pointList.size() - 2] = GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], + m_pointList[m_pointList.size() - 3]); + } + else + { + m_pointList[m_pointList.size() - 2] = m_pointList[m_pointList.size() - 1]; + } +} + +void Transformer::Move(wxPoint2DDouble position) +{ + SetPosition(m_movePos + position - m_moveStartPt); + + // Move all the points, except the switches and buses points. + for(int i = 2; i < (int)m_pointList.size() - 2; i++) { + m_pointList[i] = m_movePts[i] + position - m_moveStartPt; + } + + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + if(!m_parentList[1]) { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } + + UpdateSwitchesPosition(); +} + +void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) +{ + if(parent) { + // First bus. + if(parent == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + // Second bus. + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } + } + else + { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + m_parentList[0] = NULL; + } + else if(m_activeNodeID == 2) + { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + m_parentList[1] = NULL; + } + } + + // Recalculate switches positions + UpdateSwitchesPosition(); +} + +void Transformer::StartMove(wxPoint2DDouble position) +{ + m_moveStartPt = position; + m_movePts = m_pointList; + m_movePos = m_position; +} + +void Transformer::RemoveParent(Element* parent) +{ + for(int i = 0; i < 2; i++) { + if(parent == m_parentList[i]) { + m_parentList[i] = NULL; + m_parentList[i] = NULL; + UpdateSwitchesPosition(); + } + } +} + +bool Transformer::NodeContains(wxPoint2DDouble position) +{ + wxRect2DDouble nodeRect1(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); + wxRect2DDouble nodeRect2(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(nodeRect1.Contains(position)) { + m_activeNodeID = 1; + return true; + } + if(nodeRect2.Contains(position)) { + m_activeNodeID = 2; + return true; + } + + m_activeNodeID = 0; return false; } -bool Transformer::Contains(wxPoint2DDouble position) const {return m_rect.Contains(position);} -void Transformer::Draw(wxPoint2DDouble translation, double scale) const + +bool Transformer::SetNodeParent(Element* parent) +{ + if(m_activeNodeID == 1 && parent == m_parentList[0]) return false; + if(m_activeNodeID == 2 && parent == m_parentList[1]) return false; + + if(parent && m_activeNodeID != 0) { + wxRect2DDouble nodeRect(0, 0, 0, 0); + if(m_activeNodeID == 1) { + nodeRect = + wxRect2DDouble(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_activeNodeID == 2) { + 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(parent->Intersects(nodeRect)) { + if(m_activeNodeID == 1) { + // 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; + } + + 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; + } + } + else + { + if(m_activeNodeID == 1) m_parentList[0] = NULL; + if(m_activeNodeID == 2) m_parentList[1] = NULL; + } + } + return false; +} + +void Transformer::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(); + } + } +} + +void Transformer::RotateNode(Element* parent) +{ + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); + } + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], m_rotationAngle); + } + UpdateSwitchesPosition(); +} + +bool Transformer::GetContextMenu(wxMenu& menu) { - + menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); + menu.Append(ID_DELETE, _("Delete")); + return true; } -bool Transformer::Intersects(wxRect2DDouble rect) const { return false;} -void Transformer::Rotate() {} -void Transformer::UpdateSwitchesPosition() {} diff --git a/Project/Transformer.h b/Project/Transformer.h index 02ad59c..ce694ad 100644 --- a/Project/Transformer.h +++ b/Project/Transformer.h @@ -14,6 +14,15 @@ public: virtual void Draw(wxPoint2DDouble translation, double scale) const; virtual bool Intersects(wxRect2DDouble rect) const; virtual void Rotate(); + virtual void Move(wxPoint2DDouble position); + virtual void MoveNode(Element* parent, wxPoint2DDouble position); + virtual void StartMove(wxPoint2DDouble position); + virtual void RemoveParent(Element* parent); + virtual bool NodeContains(wxPoint2DDouble position); + virtual bool SetNodeParent(Element* parent); + virtual void UpdateNodes(); + virtual void RotateNode(Element* parent); + virtual bool GetContextMenu(wxMenu& menu); protected: void UpdateSwitchesPosition(); diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index cefbcfb..5408327 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -698,9 +698,7 @@ void Workspace::OnPopupClick(wxCommandEvent& event) m_elementList.erase(it--); } } - Redraw(); } break; } - delete menu; } |