diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2016-09-04 00:59:41 -0300 |
---|---|---|
committer | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2016-09-04 00:59:41 -0300 |
commit | c1aad656847602f7e4c7aead048f7465a76838d4 (patch) | |
tree | 2b69d1d0e98f50ed8113746c3c4a4d87d6be3b7e /Project | |
parent | 726686c9b378f3a727ded52226b13a760cba1e6c (diff) | |
download | PSP.git-c1aad656847602f7e4c7aead048f7465a76838d4.tar.gz PSP.git-c1aad656847602f7e4c7aead048f7465a76838d4.tar.xz PSP.git-c1aad656847602f7e4c7aead048f7465a76838d4.zip |
Inductor implemented
Diffstat (limited to 'Project')
21 files changed, 138 insertions, 32 deletions
diff --git a/Project/Element.h b/Project/Element.h index d15fc57..1a6b73e 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -26,6 +26,7 @@ enum ContextMenuID ID_EDIT_INDMOTOR, ID_EDIT_SYNCMOTOR, ID_EDIT_LOAD, + ID_EDIT_INDUCTOR, ID_LINE_ADD_NODE, ID_LINE_REMOVE_NODE, diff --git a/Project/Inductor.cpp b/Project/Inductor.cpp index 2659295..0ed8ba5 100644 --- a/Project/Inductor.cpp +++ b/Project/Inductor.cpp @@ -1,25 +1,101 @@ #include "Inductor.h" -Inductor::Inductor() : Shunt() +Inductor::Inductor() : Shunt() {} +Inductor::~Inductor() {} +bool Inductor::AddParent(Element* parent, wxPoint2DDouble position) { + if(parent) { + m_parentList.push_back(parent); + 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_position = parentPt + wxPoint2DDouble(0.0, 100.0); // Shifts the position to the down of the bus. + m_width = 20.0; + m_height = 70.0; + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, m_height); + + m_pointList.push_back(parentPt); + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); + m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0 - 10.0)); + m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0)); + + m_inserted = true; + return true; + } + return false; } -Inductor::~Inductor() +void Inductor::Draw(wxPoint2DDouble translation, double scale) const { + if(m_inserted) { + if(m_selected) { + glLineWidth(1.5 + m_borderSize * 2.0); + glColor4d(0.0, 0.5, 1.0, 0.5); + + DrawLine(m_pointList); + + glPushMatrix(); + 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); + + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), 10, 45, 270, 30, GL_LINE_STRIP); + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0), 10, 45, 315, 30, GL_LINE_STRIP); + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0), 10, 90, 315, 30, GL_LINE_STRIP); + + DrawGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0)); + + glPopMatrix(); + + // Draw node selection. + DrawCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, GL_POLYGON); + } + // Draw Load (layer 2). + glLineWidth(1.5); + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); + DrawLine(m_pointList); + + glPushMatrix(); + 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); + + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), 10, 45, 270, 10, GL_LINE_STRIP); + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0), 10, 45, 315, 10, GL_LINE_STRIP); + DrawArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0), 10, 90, 315, 10, GL_LINE_STRIP); + + DrawGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0)); + + glPopMatrix(); + } } -bool Inductor::AddParent(Element* parent, wxPoint2DDouble position) +void Inductor::Rotate() { + m_angle += m_rotationAngle; + m_pointList[2] = RotateAtPosition(m_pointList[2], m_rotationAngle); + m_pointList[3] = RotateAtPosition(m_pointList[3], m_rotationAngle); + UpdateSwitchesPosition(); } -void Inductor::Draw(wxPoint2DDouble translation, double scale) const +bool Inductor::GetContextMenu(wxMenu& menu) { + menu.Append(ID_EDIT_INDUCTOR, _("Edit Inductor")); + menu.Append(ID_ROTATE, _("Rotate")); + menu.Append(ID_DELETE, _("Delete")); + return true; } -void Inductor::Rotate() +bool Inductor::Contains(wxPoint2DDouble position) const { + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + return m_rect.Contains(ptR); } -bool Inductor::GetContextMenu(wxMenu& menu) +bool Inductor::Intersects(wxRect2DDouble rect) const { + return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0); } diff --git a/Project/Inductor.h b/Project/Inductor.h index 7c6b535..830cab5 100644 --- a/Project/Inductor.h +++ b/Project/Inductor.h @@ -11,6 +11,8 @@ public: virtual bool AddParent(Element* parent, wxPoint2DDouble position); virtual void Draw(wxPoint2DDouble translation, double scale) const; + virtual bool Contains(wxPoint2DDouble position) const; + virtual bool Intersects(wxRect2DDouble rect) const; virtual void Rotate(); virtual bool GetContextMenu(wxMenu& menu); }; diff --git a/Project/Load.cpp b/Project/Load.cpp index b779f35..a932c64 100644 --- a/Project/Load.cpp +++ b/Project/Load.cpp @@ -17,7 +17,7 @@ bool Load::AddParent(Element* parent, wxPoint2DDouble position) m_pointList.push_back(parentPt); m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); - m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -15.0)); + m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -20.0)); m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -10.0)); m_triangPts.push_back(wxPoint2DDouble(-m_width / 2.0, -m_height / 2.0)); diff --git a/Project/Project.mk b/Project/Project.mk index 116a8ba..958115b 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,8 +13,8 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=03/09/2016 -CodeLitePath :="C:/Program Files/CodeLite" +Date :=04/09/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)/ArtMetro.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrame.cpp$(ObjectSuffix) $(IntermediateDirectory)/Workspace.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBase.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBase.cpp$(ObjectSuffix) \ diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o Binary files differindex 6b0261e..618edb2 100644 --- a/Project/Release/Bus.cpp.o +++ b/Project/Release/Bus.cpp.o diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o Binary files differindex 0fa652c..27c098d 100644 --- a/Project/Release/IndMotor.cpp.o +++ b/Project/Release/IndMotor.cpp.o diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o Binary files differindex e432edc..c8331a3 100644 --- a/Project/Release/Inductor.cpp.o +++ b/Project/Release/Inductor.cpp.o diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o Binary files differindex f8ddccd..53db765 100644 --- a/Project/Release/Line.cpp.o +++ b/Project/Release/Line.cpp.o diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o Binary files differindex 541878f..24f2ed1 100644 --- a/Project/Release/Load.cpp.o +++ b/Project/Release/Load.cpp.o diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe Binary files differindex b31a0c3..9e65316 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o Binary files differindex 8891f4d..1b06520 100644 --- a/Project/Release/Shunt.cpp.o +++ b/Project/Release/Shunt.cpp.o diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o Binary files differindex c013ca3..982a88b 100644 --- a/Project/Release/SyncGenerator.cpp.o +++ b/Project/Release/SyncGenerator.cpp.o diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o Binary files differindex c27c9ce..78e1caf 100644 --- a/Project/Release/SyncMotor.cpp.o +++ b/Project/Release/SyncMotor.cpp.o diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o Binary files differindex c615188..23b6f1a 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 6187d39..f0e577a 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Release/Workspace.cpp.o.d b/Project/Release/Workspace.cpp.o.d index e9ce015..fd74f92 100644 --- a/Project/Release/Workspace.cpp.o.d +++ b/Project/Release/Workspace.cpp.o.d @@ -192,7 +192,7 @@ Release/Workspace.cpp.o: Workspace.cpp Workspace.h \ C:/wxWidgets-3.1.0/include/wx/msw/ownerdrw.h \ C:/wxWidgets-3.1.0/include/wx/msw/menu.h Bus.h Line.h Branch.h \ Transformer.h SyncGenerator.h Machines.h IndMotor.h SyncMotor.h Load.h \ - Shunt.h + Shunt.h Inductor.h Workspace.h: @@ -605,3 +605,5 @@ SyncMotor.h: Load.h: Shunt.h: + +Inductor.h: diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 6e55dde..34e4068 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -127,3 +127,18 @@ void Shunt::RotateNode(Element* parent) } } +void Shunt::DrawGround(wxPoint2DDouble position) const +{ + std::vector<wxPoint2DDouble> groundPts; + groundPts.push_back(position); + groundPts.push_back(position + wxPoint2DDouble(0, 10)); + groundPts.push_back(position + wxPoint2DDouble(-10, 10)); + groundPts.push_back(position + wxPoint2DDouble(10, 10)); + groundPts.push_back(position + wxPoint2DDouble(-6, 15)); + groundPts.push_back(position + wxPoint2DDouble(6, 15)); + groundPts.push_back(position + wxPoint2DDouble(-3, 20)); + groundPts.push_back(position + wxPoint2DDouble(3, 20)); + + DrawLine(groundPts, GL_LINES); +} + diff --git a/Project/Shunt.h b/Project/Shunt.h index 2d74984..9f5064a 100644 --- a/Project/Shunt.h +++ b/Project/Shunt.h @@ -22,6 +22,7 @@ public: protected: void UpdateSwitchesPosition(); + void DrawGround(wxPoint2DDouble position) const; bool m_inserted = false; std::vector<wxPoint2DDouble> m_pointList; std::vector<wxPoint2DDouble> m_movePts; diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index e5b9e3f..79bb61c 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -8,6 +8,7 @@ #include "IndMotor.h" #include "SyncMotor.h" #include "Load.h" +#include "Inductor.h" // Camera Camera::Camera() @@ -572,13 +573,21 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } } break; - case 'L': // Insert a power line. + case 'L': { if(m_mode != MODE_INSERT) { - Line* newLine = new Line(); - m_elementList.push_back(newLine); - m_mode = MODE_INSERT; - m_statusBar->SetStatusText(_("Insert Line: Click on two buses, ESC to cancel.")); + if(event.GetModifiers() == wxMOD_SHIFT) { // Insert a load. + Load* newLoad = new Load(); + m_elementList.push_back(newLoad); + m_mode = MODE_INSERT; + m_statusBar->SetStatusText(_("Insert Load: Click on a buses, ESC to cancel.")); + } + else { // Insert a power line. + Line* newLine = new Line(); + m_elementList.push_back(newLine); + m_mode = MODE_INSERT; + m_statusBar->SetStatusText(_("Insert Line: Click on two buses, ESC to cancel.")); + } Redraw(); } } @@ -605,13 +614,22 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } } break; - case 'I': // Insert an induction motor. + case 'I': { if(m_mode != MODE_INSERT) { - IndMotor* newIndMotor = new IndMotor(); - m_elementList.push_back(newIndMotor); - m_mode = MODE_INSERT; - m_statusBar->SetStatusText(_("Insert Induction Motor: Click on a buses, ESC to cancel.")); + if(event.GetModifiers() == wxMOD_SHIFT) { // Insert an inductor. + Inductor* newInductor = new Inductor(); + m_elementList.push_back(newInductor); + m_mode = MODE_INSERT; + m_statusBar->SetStatusText(_("Insert Inductor: Click on a buses, ESC to cancel.")); + } + else // Insert an induction motor. + { + IndMotor* newIndMotor = new IndMotor(); + m_elementList.push_back(newIndMotor); + m_mode = MODE_INSERT; + m_statusBar->SetStatusText(_("Insert Induction Motor: Click on a buses, ESC to cancel.")); + } Redraw(); } } @@ -627,17 +645,6 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } } break; - case 'C': // Insert a load. - { - if(m_mode != MODE_INSERT) { - Load* newLoad = new Load(); - m_elementList.push_back(newLoad); - m_mode = MODE_INSERT; - m_statusBar->SetStatusText(_("Insert Load: Click on a buses, ESC to cancel.")); - Redraw(); - } - } - break; default: break; } diff --git a/Project/Workspace.h b/Project/Workspace.h index e285ab8..b506189 100644 --- a/Project/Workspace.h +++ b/Project/Workspace.h @@ -18,6 +18,7 @@ class SyncGenerator; class IndMotor; class SyncMotor; class Load; +class Inductor; enum WorkspaceMode { |