diff options
-rw-r--r-- | Project/ControlEditor.h | 2 | ||||
-rw-r--r-- | Project/ControlEditorDC.cpp | 79 | ||||
-rw-r--r-- | Project/ControlEditorDC.h | 2 | ||||
-rw-r--r-- | Project/GeneratorStabForm.cpp | 35 | ||||
-rw-r--r-- | Project/PSP-UFU.vcxproj | 2 | ||||
-rw-r--r-- | Project/Workspace.cpp | 2 | ||||
-rw-r--r-- | Project/WorkspaceDC.cpp | 3 | ||||
-rw-r--r-- | Project/WorkspaceDC.h | 22 |
8 files changed, 120 insertions, 27 deletions
diff --git a/Project/ControlEditor.h b/Project/ControlEditor.h index 3f77422..ee6c670 100644 --- a/Project/ControlEditor.h +++ b/Project/ControlEditor.h @@ -121,7 +121,7 @@ class ControlEditor : public ControlEditorBase MODE_PASTE, MODE_DRAG_PASTE }; - + ControlEditor(wxWindow* parent) : ControlEditorBase (parent) {} ControlEditor(wxWindow* parent, wxGLContext* sharedGLContext, int ioflags = IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY | IOControl::OUT_FIELD_VOLTAGE | IOControl::OUT_MEC_POWER); diff --git a/Project/ControlEditorDC.cpp b/Project/ControlEditorDC.cpp index 84e212d..8695580 100644 --- a/Project/ControlEditorDC.cpp +++ b/Project/ControlEditorDC.cpp @@ -1,31 +1,82 @@ #include "ControlEditorDC.h" #include "Camera.h" +#include "ConnectionLine.h" -ControlEditorDC::ControlEditorDC(wxWindow* parent, int ioflags) : ControlEditor(parent, nullptr, ioflags) +ControlEditorDC::ControlEditorDC(wxWindow* parent, int ioflags) : ControlEditor(parent) { BuildControlElementPanel(); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - // m_camera->SetScale(1.2); m_ioFlags = ioflags; - - this->GetSizer()->Remove(this->GetSizer()->GetChildren()[0]->GetId()); // remove m_glCanvas object from sizer - - delete m_glCanvas; // Delete GLCanvas to allow drawing with wxDC - m_glCanvas = nullptr; - SetBackgroundColour(wxColour(255, 255, 255)); - SetBackgroundStyle(wxBG_STYLE_PAINT); // To allow wxBufferedPaintDC works properly. - Redraw(); + + // Disconnect events from GLCanvas + m_glCanvas->Disconnect(wxEVT_PAINT, wxPaintEventHandler(ControlEditor::OnPaint), NULL, this); + m_glCanvas->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::OnLeftClickDown), NULL, this); + m_glCanvas->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(ControlEditor::OnKeyDown), NULL, this); + m_glCanvas->Disconnect(wxEVT_MOTION, wxMouseEventHandler(ControlEditor::OnMouseMotion), NULL, this); + m_glCanvas->Disconnect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(ControlEditor::OnMiddleDown), NULL, this); + m_glCanvas->Disconnect(wxEVT_MIDDLE_UP, wxMouseEventHandler(ControlEditor::OnMiddleUp), NULL, this); + m_glCanvas->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlEditor::OnLeftClickUp), NULL, this); + m_glCanvas->Disconnect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(ControlEditor::OnScroll), NULL, this); + m_glCanvas->Disconnect(wxEVT_IDLE, wxIdleEventHandler(ControlEditor::OnIdle), NULL, this); + + // Reconnect events to this + m_panelWorkspace->Connect(wxEVT_PAINT, wxPaintEventHandler(ControlEditorDC::OnPaint), NULL, this); // Connect to overloaded method + m_panelWorkspace->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::OnLeftClickDown), NULL, this); + m_panelWorkspace->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(ControlEditor::OnKeyDown), NULL, this); + m_panelWorkspace->Connect(wxEVT_MOTION, wxMouseEventHandler(ControlEditor::OnMouseMotion), NULL, this); + m_panelWorkspace->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(ControlEditor::OnMiddleDown), NULL, this); + m_panelWorkspace->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(ControlEditor::OnMiddleUp), NULL, this); + m_panelWorkspace->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlEditor::OnLeftClickUp), NULL, this); + m_panelWorkspace->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(ControlEditor::OnScroll), NULL, this); + m_panelWorkspace->Connect(wxEVT_IDLE, wxIdleEventHandler(ControlEditorDC::OnIdle), NULL, this); // Connect to overloaded method + + m_panelWorkspace->GetSizer()->Remove(m_panelWorkspace->GetSizer()->GetChildren()[0]->GetId()); // remove m_glCanvas object from sizer + + delete m_glCanvas; // Delete GLcanvas to allow drawing with wxDC + m_glCanvas = nullptr; + if (m_glContext) delete m_glContext; + m_glContext = nullptr; + m_panelWorkspace->SetBackgroundColour(wxColour(255, 255, 255)); + m_panelWorkspace->SetBackgroundStyle(wxBG_STYLE_PAINT); // To allow wxBufferedPaintDC works properly. + Redraw(); } ControlEditorDC::~ControlEditorDC() { - // Recreate the GLCanvas. This is necessary to prevent WorkspaceBase destructor access nullpr. - // Also avoid the code editing of WorkspaceBase, since is automatically generated by wxCrafter. - // TODO(?): Find a better way to solve this problem. - m_glCanvas = new wxGLCanvas(this); + // Recreate the GLCanvas. This is necessary to prevent WorkspaceBase destructor access nullptr. + // Also avoid the code editing of WorkspaceBase, since is automatically generated by wxCrafter. + // TODO(?): Find a better way to solve this problem. + m_glCanvas = new wxGLCanvas(this); } void ControlEditorDC::OnPaint(wxPaintEvent& event) { + wxBufferedPaintDC dc(m_panelWorkspace); + dc.Clear(); + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + + // Draw + if (gc) { + + gc->Scale(m_camera->GetScale(), m_camera->GetScale()); + gc->Translate(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y); + + for (auto line : m_connectionList) { + //ConnectionLine* line = *it; + line->DrawDC(m_camera->GetTranslation(), m_camera->GetScale(), gc); + } + + for (auto element : m_elementList) { + element->DrawDC(m_camera->GetTranslation(), m_camera->GetScale(), gc); + } + + // Selection rectangle + gc->SetPen(wxPen(wxColour(0, 125, 255, 255))); + gc->SetBrush(wxBrush(wxColour(0, 125, 255, 125))); + gc->DrawRectangle(m_selectionRect.m_x, m_selectionRect.m_y, m_selectionRect.m_width, m_selectionRect.m_height); + + delete gc; + } + event.Skip(); } diff --git a/Project/ControlEditorDC.h b/Project/ControlEditorDC.h index 74e509a..c8325a8 100644 --- a/Project/ControlEditorDC.h +++ b/Project/ControlEditorDC.h @@ -14,7 +14,7 @@ public: IOControl::OUT_MEC_POWER); ~ControlEditorDC(); - virtual void Redraw() { this->Refresh(); } + virtual void Redraw() { m_panelWorkspace->Refresh(); } protected: virtual void OnPaint(wxPaintEvent& event); diff --git a/Project/GeneratorStabForm.cpp b/Project/GeneratorStabForm.cpp index f22ecdb..752dd3b 100644 --- a/Project/GeneratorStabForm.cpp +++ b/Project/GeneratorStabForm.cpp @@ -17,6 +17,7 @@ #include "GeneratorStabForm.h" #include "ControlEditor.h" +#include "ControlEditorDC.h" #include "ControlElementContainer.h" #include "SwitchingForm.h" #include "SyncGenerator.h" @@ -76,10 +77,22 @@ void GeneratorStabForm::OnEditAVRButtonClick(wxCommandEvent& event) data.avr = new ControlElementContainer(); m_syncGenerator->SetElectricalData(data); } - ControlEditor* cEditor = new ControlEditor(NULL, m_sharedGLContext, IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER | - IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY | - IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER | - IOControl::OUT_FIELD_VOLTAGE); + + ControlEditor* cEditor = nullptr; + + if (m_sharedGLContext) { + cEditor = new ControlEditor(nullptr, m_sharedGLContext, IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER | + IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY | + IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER | + IOControl::OUT_FIELD_VOLTAGE); + } + else { + cEditor = new ControlEditorDC(nullptr, IOControl::IN_TERMINAL_VOLTAGE | IOControl::IN_ACTIVE_POWER | + IOControl::IN_REACTIVE_POWER | IOControl::IN_INITIAL_TERMINAL_VOLTAGE | IOControl::IN_VELOCITY | + IOControl::IN_INITIAL_VELOCITY | IOControl::IN_DELTA_VELOCITY | IOControl::IN_DELTA_ACTIVE_POWER | + IOControl::OUT_FIELD_VOLTAGE); + } + cEditor->SetElementsList(data.avr->GetControlElementsList()); cEditor->SetConnectionsList(data.avr->GetConnectionLineList()); cEditor->SetControlContainer(data.avr); @@ -105,9 +118,17 @@ void GeneratorStabForm::OnSpeedGovernorButtonClick(wxCommandEvent& event) data.speedGov = new ControlElementContainer(); m_syncGenerator->SetElectricalData(data); } - ControlEditor* cEditor = - new ControlEditor(NULL, m_sharedGLContext, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER | - IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER); + ControlEditor* cEditor = nullptr; + + if (m_sharedGLContext) { + cEditor = new ControlEditor(nullptr, m_sharedGLContext, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER | + IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER); + } + else { + cEditor = new ControlEditorDC(nullptr, IOControl::IN_VELOCITY | IOControl::IN_ACTIVE_POWER | IOControl::IN_REACTIVE_POWER | + IOControl::IN_INITIAL_VELOCITY | IOControl::IN_INITIAL_MEC_POWER | IOControl::OUT_MEC_POWER); + } + cEditor->SetElementsList(data.speedGov->GetControlElementsList()); cEditor->SetConnectionsList(data.speedGov->GetConnectionLineList()); cEditor->SetControlContainer(data.speedGov); diff --git a/Project/PSP-UFU.vcxproj b/Project/PSP-UFU.vcxproj index 4c48ce2..4a4947d 100644 --- a/Project/PSP-UFU.vcxproj +++ b/Project/PSP-UFU.vcxproj @@ -191,6 +191,7 @@ <ClCompile Include="ControlEditor.cpp" /> <ClCompile Include="ControlEditorBase.cpp" /> <ClCompile Include="ControlEditorBitmaps.cpp" /> + <ClCompile Include="ControlEditorDC.cpp" /> <ClCompile Include="ControlElement.cpp" /> <ClCompile Include="ControlElementContainer.cpp" /> <ClCompile Include="ControlElementSolver.cpp" /> @@ -290,6 +291,7 @@ <ClInclude Include="ConstantForm.h" /> <ClInclude Include="ControlEditor.h" /> <ClInclude Include="ControlEditorBase.h" /> + <ClInclude Include="ControlEditorDC.h" /> <ClInclude Include="ControlElement.h" /> <ClInclude Include="ControlElementContainer.h" /> <ClInclude Include="ControlElementSolver.h" /> diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 37fb027..5b680a2 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -194,7 +194,7 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event) } } } - // The line element can have an indefined number of points. + // The line element can have an undefined number of points. if(!foundElement) { if(typeid(*newElement) == typeid(Line)) { newElement->AddPoint(m_camera->ScreenToWorld(clickPoint)); } } diff --git a/Project/WorkspaceDC.cpp b/Project/WorkspaceDC.cpp index 1333314..45ae29e 100644 --- a/Project/WorkspaceDC.cpp +++ b/Project/WorkspaceDC.cpp @@ -67,6 +67,7 @@ WorkspaceDC::WorkspaceDC(wxWindow* parent, wxString name, wxStatusBar* statusBar delete m_glCanvas; // Delete GLcanvas to allow drawing with wxDC m_glCanvas = nullptr; + m_glContext = nullptr; SetBackgroundColour(wxColour(255, 255, 255)); SetBackgroundStyle(wxBG_STYLE_PAINT); // To allow wxBufferedPaintDC works properly. Redraw(); @@ -120,10 +121,8 @@ void WorkspaceDC::OnPaint(wxPaintEvent& event) } // Selection rectangle - //dc.SetPen(wxPen(wxColour(0, 125, 255))); gc->SetPen(wxPen(wxColour(0, 125, 255, 255))); gc->SetBrush(wxBrush(wxColour(0, 125, 255, 125))); - //dc.SetBrush(wxBrush(wxColour(0, 125, 255, 125))); gc->DrawRectangle(m_selectionRect.m_x, m_selectionRect.m_y, m_selectionRect.m_width, m_selectionRect.m_height); delete gc; diff --git a/Project/WorkspaceDC.h b/Project/WorkspaceDC.h index 609663a..7eaf419 100644 --- a/Project/WorkspaceDC.h +++ b/Project/WorkspaceDC.h @@ -4,15 +4,35 @@ #include <wx/graphics.h> //#include <wx/dcclient.h> #include <wx/dcbuffer.h> - +/** + * @brief A Workspace class that draws using Device Context. +*/ class WorkspaceDC : public Workspace { public: + /** + * @brief Default constructor + */ WorkspaceDC(); + /** + * @brief WorkspaceDC constructor + * @param parent Parent window + * @param name Project name (displayed at the tabs) + * @param statusBar Status bar to show useful info + * @return + */ WorkspaceDC(wxWindow* parent, wxString name = wxEmptyString, wxStatusBar* statusBar = nullptr); ~WorkspaceDC(); + /** + * @brief Redraws the screen + */ virtual void Redraw() { this->Refresh(); } + /** + * @brief Get shared OpenGL context. This method prevents to share any OpenGL context when use DC. + * @return Aways nullptr + */ + virtual wxGLContext* GetSharedGLContext() const { return nullptr; } // Prevent share any OpenGL context when use DC protected: virtual void OnPaint(wxPaintEvent& event); |