From ddb262a4d6bed48ac68eeed99032e10c49c02996 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 18 Jan 2017 19:45:49 -0200 Subject: Control editor implementation start --- Project/ControlEditor.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Project/ControlEditor.cpp (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp new file mode 100644 index 0000000..422bfb0 --- /dev/null +++ b/Project/ControlEditor.cpp @@ -0,0 +1,11 @@ +#include "ControlEditor.h" + +ControlEditor::ControlEditor(wxWindow* parent) + : ControlEditorBase(parent) +{ +} + +ControlEditor::~ControlEditor() +{ +} + -- cgit From 864842440bb7fd9f8495314b8bfa2e2c8a0d47f4 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 19 Jan 2017 19:18:16 -0200 Subject: Cunston control element button implementation --- Project/ControlEditor.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 422bfb0..a7788f9 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -3,9 +3,119 @@ ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) { + BuildControlElementPanel(); } ControlEditor::~ControlEditor() { + // m_tfButton->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::LeftClickDown), m_tfButton, this); } +void ControlEditor::BuildControlElementPanel() +{ + m_panelControlElements->SetDoubleBuffered(true); + wxWrapSizer* wrapSizer = new wxWrapSizer(); + m_panelControlElements->SetSizer(wrapSizer); + + /*m_tfButton = new wxButton(); + m_tfButton->SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); + m_tfButton->Create(m_panelControlElements, wxID_ANY, _("Transfer function"), wxDefaultPosition, wxDefaultSize, + wxBORDER_NONE); + m_tfButton->SetTransparent(wxIMAGE_ALPHA_TRANSPARENT); + //m_tfButton = new wxButton(m_panelControlElements, wxID_ANY, _("Transfer function"), wxDefaultPosition, + wxDefaultSize, wxBORDER_NONE); + m_tfButton->SetBitmap(wxImage("..\\data\\images\\control\\transferFunc.png"), wxTOP); + // m_tfButton->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + // m_tfButton->SetToolTip(_("Transfer function")); + m_tfButton->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::LeftClickDown), NULL, this); + wrapSizer->Add(m_tfButton, 0, wxALL, 3)*/ + ControlElementButton* tfButton = new ControlElementButton( + m_panelControlElements, _("Transfer function"), wxImage("..\\data\\images\\control\\transferFunc.png")); + wrapSizer->Add(tfButton, 0, wxALL, 5); + + wxBitmapButton* tfButton2 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton2->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton2->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton2, 0, wxALL, 3); + + wxBitmapButton* tfButton3 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton3->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton3->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton3, 0, wxALL, 3); + + wxBitmapButton* tfButton4 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton4->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton4->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton4, 0, wxALL, 3); + + wxBitmapButton* tfButton5 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton5->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton5->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton5, 0, wxALL, 3); + + wxBitmapButton* tfButton6 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton6->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton6->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton6, 0, wxALL, 3); + + wxBitmapButton* tfButton7 = + new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), + wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); + tfButton7->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); + tfButton7->SetToolTip(_("Transfer function")); + + wrapSizer->Add(tfButton7, 0, wxALL, 3); + + // m_auimgr->Update(); + // Layout(); +} +void ControlEditor::LeftClickDown(wxMouseEvent& event) +{ + + wxBitmapButton* button = dynamic_cast(event.GetEventObject()); + if(button) { + button->SetOwnBackgroundColour(wxColour(wxT("rgb(0,0,255)"))); + } + event.Skip(); +} + +ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image) + : wxWindow(parent, wxID_ANY) +{ + m_label = label; + m_image = image; + SetMinSize(wxSize(32,32)); + Connect(wxEVT_PAINT, wxPaintEventHandler(ControlElementButton::OnPaint), NULL, this); +} + +ControlElementButton::~ControlElementButton() {} + +void ControlElementButton::OnPaint(wxPaintEvent& event) +{ + wxPaintDC dc(this); + //dc.SetBrush(*wxGREY_BRUSH); + //dc.DrawRectangle( 0, 0, 32, 32 ); + dc.DrawBitmap(m_image, wxPoint(0,0)); + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + if(gc) { + gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), 0, 0, 32, 32); + gc->SetBrush(wxBrush(wxColour(0,125,255,100))); + gc->DrawRectangle(0,0,32,32); + delete gc; + } +} -- cgit From 6f7aebd00330c40007b41aa6e48847695924fe29 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 20 Jan 2017 13:34:14 -0200 Subject: ControlButton fixed --- Project/ControlEditor.cpp | 166 ++++++++++++++++++++++++++++------------------ 1 file changed, 101 insertions(+), 65 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index a7788f9..1058cf2 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -17,90 +17,87 @@ void ControlEditor::BuildControlElementPanel() wxWrapSizer* wrapSizer = new wxWrapSizer(); m_panelControlElements->SetSizer(wrapSizer); - /*m_tfButton = new wxButton(); - m_tfButton->SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); - m_tfButton->Create(m_panelControlElements, wxID_ANY, _("Transfer function"), wxDefaultPosition, wxDefaultSize, - wxBORDER_NONE); - m_tfButton->SetTransparent(wxIMAGE_ALPHA_TRANSPARENT); - //m_tfButton = new wxButton(m_panelControlElements, wxID_ANY, _("Transfer function"), wxDefaultPosition, - wxDefaultSize, wxBORDER_NONE); - m_tfButton->SetBitmap(wxImage("..\\data\\images\\control\\transferFunc.png"), wxTOP); - // m_tfButton->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - // m_tfButton->SetToolTip(_("Transfer function")); - m_tfButton->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::LeftClickDown), NULL, this); - wrapSizer->Add(m_tfButton, 0, wxALL, 3)*/ + ControlElementButton* ioButton = new ControlElementButton( + m_panelControlElements, _("Input/output"), wxImage("..\\data\\images\\control\\io.png")); + wrapSizer->Add(ioButton, 0, wxALL, 5); + ControlElementButton* tfButton = new ControlElementButton( m_panelControlElements, _("Transfer function"), wxImage("..\\data\\images\\control\\transferFunc.png")); wrapSizer->Add(tfButton, 0, wxALL, 5); - wxBitmapButton* tfButton2 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton2->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton2->SetToolTip(_("Transfer function")); - - wrapSizer->Add(tfButton2, 0, wxALL, 3); - - wxBitmapButton* tfButton3 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton3->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton3->SetToolTip(_("Transfer function")); - - wrapSizer->Add(tfButton3, 0, wxALL, 3); - - wxBitmapButton* tfButton4 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton4->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton4->SetToolTip(_("Transfer function")); - - wrapSizer->Add(tfButton4, 0, wxALL, 3); - - wxBitmapButton* tfButton5 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton5->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton5->SetToolTip(_("Transfer function")); + ControlElementButton* sumButton = + new ControlElementButton(m_panelControlElements, _("Sum"), wxImage("..\\data\\images\\control\\sum.png")); + wrapSizer->Add(sumButton, 0, wxALL, 5); - wrapSizer->Add(tfButton5, 0, wxALL, 3); + ControlElementButton* valueButton = + new ControlElementButton(m_panelControlElements, _("Value"), wxImage("..\\data\\images\\control\\value.png")); + wrapSizer->Add(valueButton, 0, wxALL, 5); - wxBitmapButton* tfButton6 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton6->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton6->SetToolTip(_("Transfer function")); + ControlElementButton* limButton = new ControlElementButton( + m_panelControlElements, _("Limiter"), wxImage("..\\data\\images\\control\\limiter.png")); + wrapSizer->Add(limButton, 0, wxALL, 5); - wrapSizer->Add(tfButton6, 0, wxALL, 3); + ControlElementButton* gainButton = + new ControlElementButton(m_panelControlElements, _("Gain"), wxImage("..\\data\\images\\control\\gain.png")); + wrapSizer->Add(gainButton, 0, wxALL, 5); - wxBitmapButton* tfButton7 = - new wxBitmapButton(m_panelControlElements, wxID_ANY, wxImage("..\\data\\images\\control\\transferFunc.png"), - wxDefaultPosition, wxDLG_UNIT(m_panelControlElements, wxSize(-1, -1)), wxBU_AUTODRAW | wxBORDER_NONE); - tfButton7->SetBackgroundColour(wxColour(wxT("rgb(255,255,255)"))); - tfButton7->SetToolTip(_("Transfer function")); + ControlElementButton* multButton = new ControlElementButton( + m_panelControlElements, _("Multiplier"), wxImage("..\\data\\images\\control\\mult.png")); + wrapSizer->Add(multButton, 0, wxALL, 5); - wrapSizer->Add(tfButton7, 0, wxALL, 3); + ControlElementButton* satButton = new ControlElementButton( + m_panelControlElements, _("Saturation"), wxImage("..\\data\\images\\control\\sat.png")); + wrapSizer->Add(satButton, 0, wxALL, 5); - // m_auimgr->Update(); - // Layout(); + ControlElementButton* rateLimButton = new ControlElementButton( + m_panelControlElements, _("Rate limiter"), wxImage("..\\data\\images\\control\\rateLimiter.png")); + wrapSizer->Add(rateLimButton, 0, wxALL, 5); } + void ControlEditor::LeftClickDown(wxMouseEvent& event) { - wxBitmapButton* button = dynamic_cast(event.GetEventObject()); + /*wxBitmapButton* button = dynamic_cast(event.GetEventObject()); if(button) { button->SetOwnBackgroundColour(wxColour(wxT("rgb(0,0,255)"))); - } + }*/ event.Skip(); } ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image) : wxWindow(parent, wxID_ANY) { + m_font = wxFont(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); m_label = label; m_image = image; - SetMinSize(wxSize(32,32)); + m_imageSize = wxSize(image.GetWidth(), image.GetHeight()); + + // Calculate label size. + wxScreenDC dc; + dc.SetFont(m_font); + wxSize textSize = dc.GetTextExtent(label); + + int buttonWidth = 0; + if(textSize.GetWidth() > m_imageSize.GetWidth()) { + buttonWidth = textSize.GetWidth(); + m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize); + m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize); + } else { + buttonWidth = m_imageSize.GetWidth(); + m_imagePosition = wxPoint(m_borderSize, m_borderSize); + m_labelPosition = + wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize); + } + m_buttonSize = + wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize); + SetMinSize(m_buttonSize); + + // Conncet events. Connect(wxEVT_PAINT, wxPaintEventHandler(ControlElementButton::OnPaint), NULL, this); + Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(ControlElementButton::OnMouseEnter), NULL, this); + Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(ControlElementButton::OnMouseLeave), NULL, this); + Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlElementButton::OnLeftClickDown), NULL, this); + Connect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlElementButton::OnLeftClickUp), NULL, this); } ControlElementButton::~ControlElementButton() {} @@ -108,14 +105,53 @@ ControlElementButton::~ControlElementButton() {} void ControlElementButton::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); - //dc.SetBrush(*wxGREY_BRUSH); - //dc.DrawRectangle( 0, 0, 32, 32 ); - dc.DrawBitmap(m_image, wxPoint(0,0)); wxGraphicsContext* gc = wxGraphicsContext::Create(dc); if(gc) { - gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), 0, 0, 32, 32); - gc->SetBrush(wxBrush(wxColour(0,125,255,100))); - gc->DrawRectangle(0,0,32,32); + gc->SetPen(*wxWHITE_PEN); + gc->SetBrush(*wxWHITE_BRUSH); + gc->DrawRectangle(0, 0, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); + gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), + m_imageSize.GetHeight()); + if(m_mouseAbove) { + if(m_selected) { + gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize)); + gc->SetBrush(wxBrush(wxColour(0, 125, 255, 100))); + } else { + gc->SetPen(*wxTRANSPARENT_PEN); + gc->SetBrush(wxBrush(wxColour(0, 125, 255, 70))); + } + gc->DrawRectangle(0, 0, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); + } + gc->SetFont(m_font, *wxBLACK); + gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y); delete gc; } } + +void ControlElementButton::OnMouseEnter(wxMouseEvent& event) +{ + m_mouseAbove = true; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnMouseLeave(wxMouseEvent& event) +{ + m_mouseAbove = false; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnLeftClickDown(wxMouseEvent& event) +{ + m_selected = true; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnLeftClickUp(wxMouseEvent& event) +{ + m_selected = false; + Refresh(); + event.Skip(); +} -- cgit From 9d29dde68863f207eba2d84746cd38094810932d Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Fri, 20 Jan 2017 18:19:59 -0200 Subject: Button click event trigger implemented --- Project/ControlEditor.cpp | 121 +++++++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 45 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 1058cf2..1d1587c 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -1,11 +1,6 @@ #include "ControlEditor.h" -ControlEditor::ControlEditor(wxWindow* parent) - : ControlEditorBase(parent) -{ - BuildControlElementPanel(); -} - +ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) { BuildControlElementPanel(); } ControlEditor::~ControlEditor() { // m_tfButton->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::LeftClickDown), m_tfButton, this); @@ -17,57 +12,97 @@ void ControlEditor::BuildControlElementPanel() wxWrapSizer* wrapSizer = new wxWrapSizer(); m_panelControlElements->SetSizer(wrapSizer); - ControlElementButton* ioButton = new ControlElementButton( - m_panelControlElements, _("Input/output"), wxImage("..\\data\\images\\control\\io.png")); + ControlElementButton* ioButton = new ControlElementButton(m_panelControlElements, _("In/Out"), + wxImage("..\\data\\images\\control\\io.png"), ID_IO); wrapSizer->Add(ioButton, 0, wxALL, 5); + ioButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); ControlElementButton* tfButton = new ControlElementButton( - m_panelControlElements, _("Transfer function"), wxImage("..\\data\\images\\control\\transferFunc.png")); + m_panelControlElements, _("Transfer fcn"), wxImage("..\\data\\images\\control\\transferFunc.png"), ID_TF); wrapSizer->Add(tfButton, 0, wxALL, 5); + tfButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* sumButton = - new ControlElementButton(m_panelControlElements, _("Sum"), wxImage("..\\data\\images\\control\\sum.png")); + ControlElementButton* sumButton = new ControlElementButton(m_panelControlElements, _("Sum"), + wxImage("..\\data\\images\\control\\sum.png"), ID_SUM); wrapSizer->Add(sumButton, 0, wxALL, 5); + sumButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* valueButton = - new ControlElementButton(m_panelControlElements, _("Value"), wxImage("..\\data\\images\\control\\value.png")); - wrapSizer->Add(valueButton, 0, wxALL, 5); + ControlElementButton* constButton = new ControlElementButton( + m_panelControlElements, _("Constant"), wxImage("..\\data\\images\\control\\value.png"), ID_CONST); + wrapSizer->Add(constButton, 0, wxALL, 5); + constButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); ControlElementButton* limButton = new ControlElementButton( - m_panelControlElements, _("Limiter"), wxImage("..\\data\\images\\control\\limiter.png")); + m_panelControlElements, _("Limiter"), wxImage("..\\data\\images\\control\\limiter.png"), ID_LIMITER); wrapSizer->Add(limButton, 0, wxALL, 5); + limButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* gainButton = - new ControlElementButton(m_panelControlElements, _("Gain"), wxImage("..\\data\\images\\control\\gain.png")); + ControlElementButton* gainButton = new ControlElementButton( + m_panelControlElements, _("Gain"), wxImage("..\\data\\images\\control\\gain.png"), ID_GAIN); wrapSizer->Add(gainButton, 0, wxALL, 5); + gainButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); ControlElementButton* multButton = new ControlElementButton( - m_panelControlElements, _("Multiplier"), wxImage("..\\data\\images\\control\\mult.png")); + m_panelControlElements, _("Multiplier"), wxImage("..\\data\\images\\control\\mult.png"), ID_MULT); wrapSizer->Add(multButton, 0, wxALL, 5); + multButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* satButton = new ControlElementButton( - m_panelControlElements, _("Saturation"), wxImage("..\\data\\images\\control\\sat.png")); + ControlElementButton* satButton = new ControlElementButton(m_panelControlElements, _("Saturation"), + wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); wrapSizer->Add(satButton, 0, wxALL, 5); + satButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); ControlElementButton* rateLimButton = new ControlElementButton( - m_panelControlElements, _("Rate limiter"), wxImage("..\\data\\images\\control\\rateLimiter.png")); + m_panelControlElements, _("Rate limiter"), wxImage("..\\data\\images\\control\\rateLimiter.png"), ID_RATELIM); wrapSizer->Add(rateLimButton, 0, wxALL, 5); + rateLimButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); } void ControlEditor::LeftClickDown(wxMouseEvent& event) { - - /*wxBitmapButton* button = dynamic_cast(event.GetEventObject()); - if(button) { - button->SetOwnBackgroundColour(wxColour(wxT("rgb(0,0,255)"))); - }*/ + AddElement(static_cast(event.GetId())); event.Skip(); } -ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image) - : wxWindow(parent, wxID_ANY) +void ControlEditor::AddElement(ControlElementButtonID id) { - m_font = wxFont(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); + switch(id) { + case ID_IO: { + wxLogMessage("io"); + } break; + case ID_TF: { + wxLogMessage("tf"); + } break; + case ID_SUM: { + wxLogMessage("sum"); + } break; + case ID_CONST: { + wxLogMessage("const"); + } break; + case ID_LIMITER: { + wxLogMessage("limiter"); + } break; + case ID_GAIN: { + wxLogMessage("gain"); + } break; + case ID_MULT: { + wxLogMessage("mult"); + } break; + case ID_SAT: { + wxLogMessage("sat"); + } break; + case ID_RATELIM: { + wxLogMessage("rateLim"); + } break; + } +} + +ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) + : wxWindow(parent, id) +{ + SetBackgroundColour(*wxWHITE); + //m_font = wxFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); + m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); m_label = label; m_image = image; m_imageSize = wxSize(image.GetWidth(), image.GetHeight()); @@ -90,38 +125,34 @@ ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxI } m_buttonSize = wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize); - SetMinSize(m_buttonSize); - - // Conncet events. - Connect(wxEVT_PAINT, wxPaintEventHandler(ControlElementButton::OnPaint), NULL, this); - Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(ControlElementButton::OnMouseEnter), NULL, this); - Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(ControlElementButton::OnMouseLeave), NULL, this); - Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlElementButton::OnLeftClickDown), NULL, this); - Connect(wxEVT_LEFT_UP, wxMouseEventHandler(ControlElementButton::OnLeftClickUp), NULL, this); + SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize)); + + // Events. + Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this); + Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this); + Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this); + Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this); + Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this); } ControlElementButton::~ControlElementButton() {} - void ControlElementButton::OnPaint(wxPaintEvent& event) { wxPaintDC dc(this); wxGraphicsContext* gc = wxGraphicsContext::Create(dc); if(gc) { - gc->SetPen(*wxWHITE_PEN); - gc->SetBrush(*wxWHITE_BRUSH); - gc->DrawRectangle(0, 0, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); - gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), - m_imageSize.GetHeight()); if(m_mouseAbove) { if(m_selected) { - gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize)); + gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize - 1)); gc->SetBrush(wxBrush(wxColour(0, 125, 255, 100))); } else { gc->SetPen(*wxTRANSPARENT_PEN); gc->SetBrush(wxBrush(wxColour(0, 125, 255, 70))); } - gc->DrawRectangle(0, 0, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); + gc->DrawRectangle(m_borderSize / 2, m_borderSize / 2, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); } + gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), + m_imageSize.GetHeight()); gc->SetFont(m_font, *wxBLACK); gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y); delete gc; -- cgit From bdb0625280d827ba7333b6fc9d6c6534e0720100 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 24 Jan 2017 18:25:17 -0200 Subject: Control editor implementation start --- Project/ControlEditor.cpp | 281 +++++++++++++++++++++++++++++++++------------- 1 file changed, 204 insertions(+), 77 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 1d1587c..f75478c 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -1,6 +1,107 @@ #include "ControlEditor.h" -ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) { BuildControlElementPanel(); } +#include "Camera.h" +#include "ControlElement.h" +#include "TransferFunction.h" + +ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) + : wxWindow(parent, id) +{ + SetBackgroundColour(*wxWHITE); + // m_font = wxFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); + m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + m_label = label; + m_image = image; + m_imageSize = wxSize(image.GetWidth(), image.GetHeight()); + + // Calculate label size. + wxScreenDC dc; + dc.SetFont(m_font); + wxSize textSize = dc.GetTextExtent(label); + + int buttonWidth = 0; + if(textSize.GetWidth() > m_imageSize.GetWidth()) { + buttonWidth = textSize.GetWidth(); + m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize); + m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize); + } else { + buttonWidth = m_imageSize.GetWidth(); + m_imagePosition = wxPoint(m_borderSize, m_borderSize); + m_labelPosition = + wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize); + } + m_buttonSize = + wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize); + SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize)); + + // Events. + Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this); + Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this); + Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this); + Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this); + Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this); +} + +ControlElementButton::~ControlElementButton() {} +void ControlElementButton::OnPaint(wxPaintEvent& event) +{ + wxPaintDC dc(this); + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + if(gc) { + if(m_mouseAbove) { + if(m_selected) { + gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize - 1)); + gc->SetBrush(wxBrush(wxColour(0, 125, 255, 100))); + } else { + gc->SetPen(*wxTRANSPARENT_PEN); + gc->SetBrush(wxBrush(wxColour(0, 125, 255, 70))); + } + gc->DrawRectangle(m_borderSize / 2, m_borderSize / 2, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); + } + gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), + m_imageSize.GetHeight()); + gc->SetFont(m_font, *wxBLACK); + gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y); + delete gc; + } +} + +void ControlElementButton::OnMouseEnter(wxMouseEvent& event) +{ + m_mouseAbove = true; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnMouseLeave(wxMouseEvent& event) +{ + m_mouseAbove = false; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnLeftClickDown(wxMouseEvent& event) +{ + m_selected = true; + Refresh(); + event.Skip(); +} + +void ControlElementButton::OnLeftClickUp(wxMouseEvent& event) +{ + m_selected = false; + Refresh(); + event.Skip(); +} + +ControlEditor::ControlEditor(wxWindow* parent) + : ControlEditorBase(parent) +{ + BuildControlElementPanel(); + m_glContext = new wxGLContext(m_glCanvas); + m_camera = new Camera(); + m_selectionRect = wxRect2DDouble(0, 0, 0, 0); +} ControlEditor::~ControlEditor() { // m_tfButton->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(ControlEditor::LeftClickDown), m_tfButton, this); @@ -12,8 +113,8 @@ void ControlEditor::BuildControlElementPanel() wxWrapSizer* wrapSizer = new wxWrapSizer(); m_panelControlElements->SetSizer(wrapSizer); - ControlElementButton* ioButton = new ControlElementButton(m_panelControlElements, _("In/Out"), - wxImage("..\\data\\images\\control\\io.png"), ID_IO); + ControlElementButton* ioButton = new ControlElementButton( + m_panelControlElements, _("In/Out"), wxImage("..\\data\\images\\control\\io.png"), ID_IO); wrapSizer->Add(ioButton, 0, wxALL, 5); ioButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -22,8 +123,8 @@ void ControlEditor::BuildControlElementPanel() wrapSizer->Add(tfButton, 0, wxALL, 5); tfButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* sumButton = new ControlElementButton(m_panelControlElements, _("Sum"), - wxImage("..\\data\\images\\control\\sum.png"), ID_SUM); + ControlElementButton* sumButton = new ControlElementButton( + m_panelControlElements, _("Sum"), wxImage("..\\data\\images\\control\\sum.png"), ID_SUM); wrapSizer->Add(sumButton, 0, wxALL, 5); sumButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -47,8 +148,8 @@ void ControlEditor::BuildControlElementPanel() wrapSizer->Add(multButton, 0, wxALL, 5); multButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* satButton = new ControlElementButton(m_panelControlElements, _("Saturation"), - wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); + ControlElementButton* satButton = new ControlElementButton( + m_panelControlElements, _("Saturation"), wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); wrapSizer->Add(satButton, 0, wxALL, 5); satButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -64,6 +165,31 @@ void ControlEditor::LeftClickDown(wxMouseEvent& event) event.Skip(); } +void ControlEditor::SetViewport() +{ + glClearColor(1.0, 1.0, 1.0, 1.0); // White background. + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_LINE_SMOOTH); + + double width = m_glCanvas->GetSize().x - 1; + double height = m_glCanvas->GetSize().y - 1; + + // Viewport fit the screen. + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.0, width, height, 0.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + void ControlEditor::AddElement(ControlElementButtonID id) { switch(id) { @@ -97,92 +223,93 @@ void ControlEditor::AddElement(ControlElementButtonID id) } } -ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) - : wxWindow(parent, id) +void ControlEditor::OnPaint(wxPaintEvent& event) { - SetBackgroundColour(*wxWHITE); - //m_font = wxFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); - m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); - m_label = label; - m_image = image; - m_imageSize = wxSize(image.GetWidth(), image.GetHeight()); + wxPaintDC dc(m_glCanvas); + m_glContext->SetCurrent(*m_glCanvas); + SetViewport(); - // Calculate label size. - wxScreenDC dc; - dc.SetFont(m_font); - wxSize textSize = dc.GetTextExtent(label); + // Set GLCanvas scale and translation. + glScaled(m_camera->GetScale(), m_camera->GetScale(), 0.0); // Scale + glTranslated(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y, 0.0); // Translation - int buttonWidth = 0; - if(textSize.GetWidth() > m_imageSize.GetWidth()) { - buttonWidth = textSize.GetWidth(); - m_imagePosition = wxPoint((buttonWidth - m_imageSize.GetWidth()) / 2 + m_borderSize, m_borderSize); - m_labelPosition = wxPoint(m_borderSize, m_imageSize.GetHeight() + m_borderSize); - } else { - buttonWidth = m_imageSize.GetWidth(); - m_imagePosition = wxPoint(m_borderSize, m_borderSize); - m_labelPosition = - wxPoint((buttonWidth - textSize.GetWidth()) / 2 + m_borderSize, m_imageSize.GetHeight() + m_borderSize); - } - m_buttonSize = - wxSize(buttonWidth + 2 * m_borderSize, textSize.GetHeight() + m_imageSize.GetHeight() + 2 * m_borderSize); - SetMinSize(m_buttonSize + wxSize(m_borderSize, m_borderSize)); + // Selection rectangle + glLineWidth(1.0); + glColor4d(0.0, 0.5, 1.0, 1.0); + glBegin(GL_LINE_LOOP); + glVertex2d(m_selectionRect.m_x, m_selectionRect.m_y); + glVertex2d(m_selectionRect.m_x, m_selectionRect.m_y + m_selectionRect.m_height); + glVertex2d(m_selectionRect.m_x + m_selectionRect.m_width, m_selectionRect.m_y + m_selectionRect.m_height); + glVertex2d(m_selectionRect.m_x + m_selectionRect.m_width, m_selectionRect.m_y); + glEnd(); + glColor4d(0.0, 0.5, 1.0, 0.3); + glBegin(GL_QUADS); + glVertex2d(m_selectionRect.m_x, m_selectionRect.m_y); + glVertex2d(m_selectionRect.m_x, m_selectionRect.m_y + m_selectionRect.m_height); + glVertex2d(m_selectionRect.m_x + m_selectionRect.m_width, m_selectionRect.m_y + m_selectionRect.m_height); + glVertex2d(m_selectionRect.m_x + m_selectionRect.m_width, m_selectionRect.m_y); + glEnd(); - // Events. - Bind(wxEVT_PAINT, &ControlElementButton::OnPaint, this); - Bind(wxEVT_ENTER_WINDOW, &ControlElementButton::OnMouseEnter, this); - Bind(wxEVT_LEAVE_WINDOW, &ControlElementButton::OnMouseLeave, this); - Bind(wxEVT_LEFT_DOWN, &ControlElementButton::OnLeftClickDown, this); - Bind(wxEVT_LEFT_UP, &ControlElementButton::OnLeftClickUp, this); + glFlush(); // Sends all pending information directly to the GPU. + m_glCanvas->SwapBuffers(); + event.Skip(); } +void ControlEditor::OnDoubleClick(wxMouseEvent& event) {} -ControlElementButton::~ControlElementButton() {} -void ControlElementButton::OnPaint(wxPaintEvent& event) +void ControlEditor::OnLeftClickDown(wxMouseEvent& event) { - wxPaintDC dc(this); - wxGraphicsContext* gc = wxGraphicsContext::Create(dc); - if(gc) { - if(m_mouseAbove) { - if(m_selected) { - gc->SetPen(wxPen(wxColour(0, 125, 255, 255), m_borderSize - 1)); - gc->SetBrush(wxBrush(wxColour(0, 125, 255, 100))); - } else { - gc->SetPen(*wxTRANSPARENT_PEN); - gc->SetBrush(wxBrush(wxColour(0, 125, 255, 70))); - } - gc->DrawRectangle(m_borderSize / 2, m_borderSize / 2, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); - } - gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), - m_imageSize.GetHeight()); - gc->SetFont(m_font, *wxBLACK); - gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y); - delete gc; - } -} + wxPoint2DDouble clickPoint = event.GetPosition(); -void ControlElementButton::OnMouseEnter(wxMouseEvent& event) -{ - m_mouseAbove = true; - Refresh(); - event.Skip(); -} + m_mode = MODE_SELECTION_RECT; + m_startSelRect = m_camera->ScreenToWorld(clickPoint); -void ControlElementButton::OnMouseLeave(wxMouseEvent& event) -{ - m_mouseAbove = false; - Refresh(); + Redraw(); event.Skip(); } -void ControlElementButton::OnLeftClickDown(wxMouseEvent& event) +void ControlEditor::OnLeftClickUp(wxMouseEvent& event) { - m_selected = true; - Refresh(); + if(m_mode != MODE_INSERT) { + m_mode = MODE_EDIT; + } + m_selectionRect = wxRect2DDouble(0, 0, 0, 0); + Redraw(); event.Skip(); } -void ControlElementButton::OnLeftClickUp(wxMouseEvent& event) +void ControlEditor::OnMiddleDown(wxMouseEvent& event) {} +void ControlEditor::OnMiddleUp(wxMouseEvent& event) {} + +void ControlEditor::OnMouseMotion(wxMouseEvent& event) { - m_selected = false; - Refresh(); + wxPoint2DDouble clickPoint = event.GetPosition(); + bool redraw = false; + + switch(m_mode) { + case MODE_SELECTION_RECT: { + wxPoint2DDouble currentPos = m_camera->ScreenToWorld(clickPoint); + double x, y, w, h; + if(currentPos.m_x < m_startSelRect.m_x) { + x = currentPos.m_x; + w = m_startSelRect.m_x - currentPos.m_x; + } else { + x = m_startSelRect.m_x; + w = currentPos.m_x - m_startSelRect.m_x; + } + if(currentPos.m_y < m_startSelRect.m_y) { + y = currentPos.m_y; + h = m_startSelRect.m_y - currentPos.m_y; + } else { + y = m_startSelRect.m_y; + h = currentPos.m_y - m_startSelRect.m_y; + } + + m_selectionRect = wxRect2DDouble(x, y, w, h); + redraw = true; + } break; + default: + break; + } + if(redraw) Redraw(); event.Skip(); } -- cgit From 9f17be8af02011f04d188ce991921f6eb0ecf792 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 25 Jan 2017 19:45:45 -0200 Subject: Several graphic tools implemented, tf start --- Project/ControlEditor.cpp | 123 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index f75478c..03cbfdf 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -197,7 +197,9 @@ void ControlEditor::AddElement(ControlElementButtonID id) wxLogMessage("io"); } break; case ID_TF: { - wxLogMessage("tf"); + m_mode = MODE_INSERT; + TransferFunction* tf = new TransferFunction(); + m_elementList.push_back(tf); } break; case ID_SUM: { wxLogMessage("sum"); @@ -233,6 +235,11 @@ void ControlEditor::OnPaint(wxPaintEvent& event) glScaled(m_camera->GetScale(), m_camera->GetScale(), 0.0); // Scale glTranslated(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y, 0.0); // Translation + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + Element* element = *it; + element->Draw(m_camera->GetTranslation(), m_camera->GetScale()); + } + // Selection rectangle glLineWidth(1.0); glColor4d(0.0, 0.5, 1.0, 1.0); @@ -254,14 +261,38 @@ void ControlEditor::OnPaint(wxPaintEvent& event) m_glCanvas->SwapBuffers(); event.Skip(); } + void ControlEditor::OnDoubleClick(wxMouseEvent& event) {} void ControlEditor::OnLeftClickDown(wxMouseEvent& event) { wxPoint2DDouble clickPoint = event.GetPosition(); + bool foundElement = false; + + if(m_mode == MODE_INSERT) { + m_mode = MODE_EDIT; + } else { + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + Element* element = *it; + + // Set movement initial position (not necessarily will be moved). + element->StartMove(m_camera->ScreenToWorld(clickPoint)); + + // Click in an element. + if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { + if(!foundElement) { + element->SetSelected(); + foundElement = true; + } + m_mode = MODE_MOVE_ELEMENT; + } + } + } - m_mode = MODE_SELECTION_RECT; - m_startSelRect = m_camera->ScreenToWorld(clickPoint); + if(!foundElement) { + m_mode = MODE_SELECTION_RECT; + m_startSelRect = m_camera->ScreenToWorld(clickPoint); + } Redraw(); event.Skip(); @@ -269,16 +300,65 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) void ControlEditor::OnLeftClickUp(wxMouseEvent& event) { + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; it++) { + Element* element = *it; + if(m_mode == MODE_SELECTION_RECT) { + if(element->Intersects(m_selectionRect)) { + element->SetSelected(); + } else if(!event.ControlDown()) { + element->SetSelected(false); + } + } else if(!event.ControlDown()) { + if(!element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + element->SetSelected(false); + } + } + } + + m_selectionRect = wxRect2DDouble(0, 0, 0, 0); if(m_mode != MODE_INSERT) { m_mode = MODE_EDIT; } - m_selectionRect = wxRect2DDouble(0, 0, 0, 0); + Redraw(); event.Skip(); } -void ControlEditor::OnMiddleDown(wxMouseEvent& event) {} -void ControlEditor::OnMiddleUp(wxMouseEvent& event) {} +void ControlEditor::OnMiddleDown(wxMouseEvent& event) +{ + // Set to drag mode. + switch(m_mode) { + case MODE_INSERT: { + m_mode = MODE_DRAG_INSERT; + } break; + case MODE_PASTE: { + m_mode = MODE_DRAG_PASTE; + } break; + default: { + m_mode = MODE_DRAG; + } break; + } + m_camera->StartTranslation(m_camera->ScreenToWorld(event.GetPosition())); +} + +void ControlEditor::OnMiddleUp(wxMouseEvent& event) +{ + switch(m_mode) { + case MODE_DRAG_INSERT: { + m_mode = MODE_INSERT; + } break; + case MODE_DRAG_PASTE: { + m_mode = MODE_PASTE; + } break; + case MODE_INSERT: + case MODE_PASTE: { + // Does nothing. + } break; + default: { + m_mode = MODE_EDIT; + } break; + } +} void ControlEditor::OnMouseMotion(wxMouseEvent& event) { @@ -286,6 +366,26 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) bool redraw = false; switch(m_mode) { + case MODE_INSERT: { + Element* newElement = *(m_elementList.end() - 1); // Get the last element in the list. + newElement->SetPosition(m_camera->ScreenToWorld(clickPoint)); + redraw = true; + } break; + case MODE_DRAG: + case MODE_DRAG_INSERT: + case MODE_DRAG_PASTE: { + m_camera->SetTranslation(clickPoint); + redraw = true; + } break; + case MODE_MOVE_ELEMENT: { + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; it++) { + Element* element = *it; + if(element->IsSelected()) { + element->Move(m_camera->ScreenToWorld(clickPoint)); + redraw = true; + } + } + } break; case MODE_SELECTION_RECT: { wxPoint2DDouble currentPos = m_camera->ScreenToWorld(clickPoint); double x, y, w, h; @@ -310,6 +410,17 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) default: break; } + if(redraw) Redraw(); event.Skip(); } + +void ControlEditor::OnScroll(wxMouseEvent& event) +{ + if(event.GetWheelRotation() > 0) + m_camera->SetScale(event.GetPosition(), +0.05); + else + m_camera->SetScale(event.GetPosition(), -0.05); + + Redraw(); +} -- cgit From 10bb7105946bc0a892a9daf42ec5181ad9994fcf Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 27 Jan 2017 19:57:18 -0200 Subject: several control elements methods implemented Node position buggy --- Project/ControlEditor.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 03cbfdf..80c0813 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -273,18 +273,30 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) m_mode = MODE_EDIT; } else { for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { - Element* element = *it; - - // Set movement initial position (not necessarily will be moved). - element->StartMove(m_camera->ScreenToWorld(clickPoint)); - - // Click in an element. - if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { - if(!foundElement) { - element->SetSelected(); + ControlElement* element = *it; + bool foundNode = false; + auto nodeList = element->GetNodeList(); + for(auto itN = nodeList.begin(), itNEnd = nodeList.end(); itN != itNEnd; ++itN) { + Node node = *itN; + if(node.Contains(m_camera->ScreenToWorld(clickPoint))) { + wxLogMessage("Node click!"); + foundNode = true; foundElement = true; } - m_mode = MODE_MOVE_ELEMENT; + } + + if(!foundNode) { + // Set movement initial position (not necessarily will be moved). + element->StartMove(m_camera->ScreenToWorld(clickPoint)); + + // Click in an element. + if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { + if(!foundElement) { + element->SetSelected(); + foundElement = true; + } + m_mode = MODE_MOVE_ELEMENT; + } } } } @@ -368,7 +380,7 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) switch(m_mode) { case MODE_INSERT: { Element* newElement = *(m_elementList.end() - 1); // Get the last element in the list. - newElement->SetPosition(m_camera->ScreenToWorld(clickPoint)); + newElement->Move(m_camera->ScreenToWorld(clickPoint)); redraw = true; } break; case MODE_DRAG: @@ -424,3 +436,15 @@ void ControlEditor::OnScroll(wxMouseEvent& event) Redraw(); } +void ControlEditor::OnIdle(wxIdleEvent& event) +{ + // Solve wxGLString bug. + if(m_firstDraw) { + TransferFunction* tf = new TransferFunction(); + m_elementList.push_back(tf); + Redraw(); + m_elementList.pop_back(); + delete tf; + m_firstDraw = false; + } +} -- cgit From 5e7c19ae397164dd718b2593663cee5d1be687cd Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Sat, 28 Jan 2017 14:50:12 -0200 Subject: Node bug fixes, tf form implemented --- Project/ControlEditor.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 80c0813..cf79283 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -262,7 +262,23 @@ void ControlEditor::OnPaint(wxPaintEvent& event) event.Skip(); } -void ControlEditor::OnDoubleClick(wxMouseEvent& event) {} +void ControlEditor::OnDoubleClick(wxMouseEvent& event) +{ + wxPoint2DDouble clickPoint = event.GetPosition(); + bool redraw = false; + + if(m_mode == MODE_EDIT) { + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + Element* element = *it; + if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { + element->ShowForm(this, element); + redraw = true; + } + } + } + + if(redraw) Redraw(); +} void ControlEditor::OnLeftClickDown(wxMouseEvent& event) { @@ -284,7 +300,7 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) foundElement = true; } } - + if(!foundNode) { // Set movement initial position (not necessarily will be moved). element->StartMove(m_camera->ScreenToWorld(clickPoint)); -- cgit From 4ddc7be64451db873e49169e951532ce8893e359 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 3 Mar 2017 18:50:40 -0300 Subject: More connection line methods implemented --- Project/ControlEditor.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 7 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index cf79283..bfc81ad 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -3,6 +3,7 @@ #include "Camera.h" #include "ControlElement.h" #include "TransferFunction.h" +#include "ConnectionLine.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -235,6 +236,11 @@ void ControlEditor::OnPaint(wxPaintEvent& event) glScaled(m_camera->GetScale(), m_camera->GetScale(), 0.0); // Scale glTranslated(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y, 0.0); // Translation + for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { + ConnectionLine* line = *it; + line->Draw(m_camera->GetTranslation(), m_camera->GetScale()); + } + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { Element* element = *it; element->Draw(m_camera->GetTranslation(), m_camera->GetScale()); @@ -293,11 +299,15 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) bool foundNode = false; auto nodeList = element->GetNodeList(); for(auto itN = nodeList.begin(), itNEnd = nodeList.end(); itN != itNEnd; ++itN) { - Node node = *itN; - if(node.Contains(m_camera->ScreenToWorld(clickPoint))) { - wxLogMessage("Node click!"); - foundNode = true; + Node* node = *itN; + if(node->Contains(m_camera->ScreenToWorld(clickPoint))) { + m_mode = MODE_INSERT_LINE; + ConnectionLine* line = new ConnectionLine(node); + m_connectionList.push_back(line); + element->AddChild(line); + line->AddParent(element); foundElement = true; + foundNode = true; } } @@ -315,6 +325,17 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) } } } + if(m_mode != MODE_INSERT_LINE) { + for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { + ConnectionLine* line = *it; + line->StartMove(m_camera->ScreenToWorld(clickPoint)); + if(line->Contains(m_camera->ScreenToWorld(clickPoint))) { + line->SetSelected(); + foundElement = true; + m_mode = MODE_MOVE_LINE; + } + } + } } if(!foundElement) { @@ -328,9 +349,25 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) void ControlEditor::OnLeftClickUp(wxMouseEvent& event) { + bool foundNode = false; for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; it++) { - Element* element = *it; - if(m_mode == MODE_SELECTION_RECT) { + ControlElement* element = *it; + if(m_mode == MODE_INSERT_LINE) { + auto nodeList = element->GetNodeList(); + for(auto itN = nodeList.begin(), itNEnd = nodeList.end(); itN != itNEnd; ++itN) { + Node* node = *itN; + if(node->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + ConnectionLine* line = *(m_connectionList.end() - 1); + if(line->AppendNode(node, element)) { + line->AddParent(element); + element->AddChild(line); + line->UpdatePoints(); + m_mode = MODE_EDIT; + foundNode = true; + } + } + } + } else if(m_mode == MODE_SELECTION_RECT) { if(element->Intersects(m_selectionRect)) { element->SetSelected(); } else if(!event.ControlDown()) { @@ -342,9 +379,34 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) } } } + for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { + ConnectionLine* line = *it; + if(m_mode == MODE_SELECTION_RECT) { + if(line->Intersects(m_selectionRect)) { + line->SetSelected(); + } else if(!event.ControlDown()) { + line->SetSelected(false); + } + } else if(!event.ControlDown()) { + if(!line->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + line->SetSelected(false); + } + } + } m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - if(m_mode != MODE_INSERT) { + + if(m_mode == MODE_INSERT_LINE && !foundNode) { + ConnectionLine* line = *(m_connectionList.end() - 1); + auto parentList = line->GetParentList(); + for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) { + Element* element = *it; + element->RemoveChild(line); + } + delete line; + m_connectionList.pop_back(); + m_mode = MODE_EDIT; + } else if(m_mode != MODE_INSERT) { m_mode = MODE_EDIT; } @@ -399,6 +461,12 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) newElement->Move(m_camera->ScreenToWorld(clickPoint)); redraw = true; } break; + case MODE_INSERT_LINE: { + ConnectionLine* line = *(m_connectionList.end() - 1); + line->SetTemporarySecondPoint(m_camera->ScreenToWorld(clickPoint)); + line->UpdatePoints(); + redraw = true; + } break; case MODE_DRAG: case MODE_DRAG_INSERT: case MODE_DRAG_PASTE: { @@ -410,6 +478,20 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) Element* element = *it; if(element->IsSelected()) { element->Move(m_camera->ScreenToWorld(clickPoint)); + auto childList = element->GetChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; itC++) { + ConnectionLine* line = static_cast(*itC); + line->UpdatePoints(); + } + redraw = true; + } + } + } break; + case MODE_MOVE_LINE: { + for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; it++) { + ConnectionLine* line = *it; + if(line->IsSelected()) { + line->Move(m_camera->ScreenToWorld(clickPoint)); redraw = true; } } @@ -464,3 +546,31 @@ void ControlEditor::OnIdle(wxIdleEvent& event) m_firstDraw = false; } } +void ControlEditor::OnKeyDown(wxKeyEvent& event) +{ + char key = event.GetUnicodeKey(); + if(key != WXK_NONE) { + switch(key) { + case 'R': // Rotate the selected elements. + { + RotateSelectedElements(event.GetModifiers() != wxMOD_SHIFT); + } break; + } + } +} + +void ControlEditor::RotateSelectedElements(bool clockwise) +{ + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + Element* element = *it; + if(element->IsSelected()) { + element->Rotate(clockwise); + auto childList = element->GetChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; itC++) { + ConnectionLine* line = static_cast(*itC); + line->UpdatePoints(); + } + } + } + Redraw(); +} -- cgit From d11da00a993f1eeae6a1be50839ac72740e4e27b Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Sat, 4 Mar 2017 17:14:52 -0300 Subject: Delete element implemented --- Project/ControlEditor.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index bfc81ad..84a2650 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -278,6 +278,11 @@ void ControlEditor::OnDoubleClick(wxMouseEvent& event) Element* element = *it; if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { element->ShowForm(this, element); + auto childList = element->GetChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { + ConnectionLine* line = static_cast(*itC); + line->UpdatePoints(); + } redraw = true; } } @@ -398,13 +403,20 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) if(m_mode == MODE_INSERT_LINE && !foundNode) { ConnectionLine* line = *(m_connectionList.end() - 1); + // Free nodes + auto nodeList = line->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetConnected(false); + } + // Remove the associated child from parents. auto parentList = line->GetParentList(); for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) { Element* element = *it; element->RemoveChild(line); } - delete line; m_connectionList.pop_back(); + if(line) delete line; m_mode = MODE_EDIT; } else if(m_mode != MODE_INSERT) { m_mode = MODE_EDIT; @@ -551,6 +563,10 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) char key = event.GetUnicodeKey(); if(key != WXK_NONE) { switch(key) { + case WXK_DELETE: // Delete selected elements. + { + DeleteSelectedElements(); + } break; case 'R': // Rotate the selected elements. { RotateSelectedElements(event.GetModifiers() != wxMOD_SHIFT); @@ -574,3 +590,61 @@ void ControlEditor::RotateSelectedElements(bool clockwise) } Redraw(); } + +void ControlEditor::DeleteSelectedElements() +{ + for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { + Element* element = *it; + if(element->IsSelected()) { + // Remove child/parent. + auto childList = element->GetChildList(); + for(auto itC = childList.begin(), itEnd = childList.end(); itC != itEnd; ++itC) { + // The child is always a connection line. + ConnectionLine* child = static_cast(*itC); + // Delete the connection line. + for(auto itCo = m_connectionList.begin(); itCo != m_connectionList.end(); ++itCo) { + ConnectionLine* line = *itCo; + if(line == child) { + // Free nodes + auto nodeList = line->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetConnected(false); + } + // Remove the child from parents + auto parentList = line->GetParentList(); + for(auto itP = parentList.begin(), itEndP = parentList.end(); itP != itEndP; ++itP) { + Element* parent = *itP; + parent->RemoveChild(child); + } + m_connectionList.erase(itCo--); + if(line) delete line; + break; + } + } + } + m_elementList.erase(it--); + if(element) delete element; + } + } + + for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) { + ConnectionLine* line = *it; + if(line->IsSelected()) { + auto parentList = line->GetParentList(); + for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { + Element* parent = *itP; + if(parent) parent->RemoveChild(line); + } + // Free nodes + auto nodeList = line->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetConnected(false); + } + m_connectionList.erase(it--); + if(line) delete line; + } + } + Redraw(); +} -- cgit From b3be8e8ef6338bce2106d9c161bf3c7f7f7f9244 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 6 Mar 2017 18:59:37 -0300 Subject: Connection line fully implemented Bug on delete a chid line and update points --- Project/ControlEditor.cpp | 93 +++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 39 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 84a2650..4e04fb1 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -385,16 +385,25 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) } } for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { - ConnectionLine* line = *it; - if(m_mode == MODE_SELECTION_RECT) { - if(line->Intersects(m_selectionRect)) { - line->SetSelected(); + ConnectionLine* cLine = *it; + if(m_mode == MODE_INSERT_LINE && !foundNode && it != (itEnd - 1)) { + if(cLine->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + ConnectionLine* iLine = *(m_connectionList.end() - 1); + cLine->AddChild(iLine); + iLine->SetParentLine(cLine); + iLine->UpdatePoints(); + m_mode = MODE_EDIT; + foundNode = true; + } + } else if(m_mode == MODE_SELECTION_RECT) { + if(cLine->Intersects(m_selectionRect)) { + cLine->SetSelected(); } else if(!event.ControlDown()) { - line->SetSelected(false); + cLine->SetSelected(false); } } else if(!event.ControlDown()) { - if(!line->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { - line->SetSelected(false); + if(!cLine->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + cLine->SetSelected(false); } } } @@ -402,21 +411,21 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) m_selectionRect = wxRect2DDouble(0, 0, 0, 0); if(m_mode == MODE_INSERT_LINE && !foundNode) { - ConnectionLine* line = *(m_connectionList.end() - 1); + ConnectionLine* cLine = *(m_connectionList.end() - 1); // Free nodes - auto nodeList = line->GetNodeList(); + auto nodeList = cLine->GetNodeList(); for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { Node* node = *itN; node->SetConnected(false); } // Remove the associated child from parents. - auto parentList = line->GetParentList(); + auto parentList = cLine->GetParentList(); for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) { Element* element = *it; - element->RemoveChild(line); + element->RemoveChild(cLine); } m_connectionList.pop_back(); - if(line) delete line; + if(cLine) delete cLine; m_mode = MODE_EDIT; } else if(m_mode != MODE_INSERT) { m_mode = MODE_EDIT; @@ -605,20 +614,7 @@ void ControlEditor::DeleteSelectedElements() for(auto itCo = m_connectionList.begin(); itCo != m_connectionList.end(); ++itCo) { ConnectionLine* line = *itCo; if(line == child) { - // Free nodes - auto nodeList = line->GetNodeList(); - for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { - Node* node = *itN; - node->SetConnected(false); - } - // Remove the child from parents - auto parentList = line->GetParentList(); - for(auto itP = parentList.begin(), itEndP = parentList.end(); itP != itEndP; ++itP) { - Element* parent = *itP; - parent->RemoveChild(child); - } - m_connectionList.erase(itCo--); - if(line) delete line; + itCo = DeleteLineFromList(itCo); break; } } @@ -631,20 +627,39 @@ void ControlEditor::DeleteSelectedElements() for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) { ConnectionLine* line = *it; if(line->IsSelected()) { - auto parentList = line->GetParentList(); - for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { - Element* parent = *itP; - if(parent) parent->RemoveChild(line); - } - // Free nodes - auto nodeList = line->GetNodeList(); - for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { - Node* node = *itN; - node->SetConnected(false); - } - m_connectionList.erase(it--); - if(line) delete line; + it = DeleteLineFromList(it); } } Redraw(); } + +std::vector::iterator ControlEditor::DeleteLineFromList(std::vector::iterator& it) +{ + ConnectionLine* cLine = *it; + auto childList = cLine->GetLineChildList(); + for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { + ConnectionLine* child = *itC; + //child->GetParentLine()->RemoveChild(child); Error + for(auto itL = m_connectionList.begin(); itL != m_connectionList.end(); ++itL) { + ConnectionLine* childOnList = *itL; + if(childOnList == child) { + itL = DeleteLineFromList(itL); + } + } + } + wxMessageBox(wxString::Format("%d", (int)cLine->GetChildList().size())); + auto parentList = cLine->GetParentList(); + for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { + Element* parent = *itP; + if(parent) parent->RemoveChild(cLine); + } + // Free nodes + auto nodeList = cLine->GetNodeList(); + for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + node->SetConnected(false); + } + m_connectionList.erase(it--); + if(cLine) delete cLine; + return it; +} -- cgit From 009849e49967af659354a94a16c51cab5eb8b5a4 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 7 Mar 2017 19:19:57 -0300 Subject: Sum implementation start --- Project/ControlEditor.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 4e04fb1..3638a42 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -4,6 +4,7 @@ #include "ControlElement.h" #include "TransferFunction.h" #include "ConnectionLine.h" +#include "Sum.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -102,6 +103,7 @@ ControlEditor::ControlEditor(wxWindow* parent) m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); + //m_camera->SetScale(1.2); } ControlEditor::~ControlEditor() { @@ -203,7 +205,9 @@ void ControlEditor::AddElement(ControlElementButtonID id) m_elementList.push_back(tf); } break; case ID_SUM: { - wxLogMessage("sum"); + m_mode = MODE_INSERT; + Sum* sum = new Sum(); + m_elementList.push_back(sum); } break; case ID_CONST: { wxLogMessage("const"); @@ -389,11 +393,12 @@ void ControlEditor::OnLeftClickUp(wxMouseEvent& event) if(m_mode == MODE_INSERT_LINE && !foundNode && it != (itEnd - 1)) { if(cLine->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { ConnectionLine* iLine = *(m_connectionList.end() - 1); - cLine->AddChild(iLine); - iLine->SetParentLine(cLine); - iLine->UpdatePoints(); - m_mode = MODE_EDIT; - foundNode = true; + if(iLine->SetParentLine(cLine)) { + cLine->AddChild(iLine); + iLine->UpdatePoints(); + m_mode = MODE_EDIT; + foundNode = true; + } } } else if(m_mode == MODE_SELECTION_RECT) { if(cLine->Intersects(m_selectionRect)) { @@ -639,7 +644,6 @@ std::vector::iterator ControlEditor::DeleteLineFromList(std::ve auto childList = cLine->GetLineChildList(); for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { ConnectionLine* child = *itC; - //child->GetParentLine()->RemoveChild(child); Error for(auto itL = m_connectionList.begin(); itL != m_connectionList.end(); ++itL) { ConnectionLine* childOnList = *itL; if(childOnList == child) { @@ -647,12 +651,13 @@ std::vector::iterator ControlEditor::DeleteLineFromList(std::ve } } } - wxMessageBox(wxString::Format("%d", (int)cLine->GetChildList().size())); + // Remove auto parentList = cLine->GetParentList(); for(auto itP = parentList.begin(), itEnd = parentList.end(); itP != itEnd; ++itP) { Element* parent = *itP; if(parent) parent->RemoveChild(cLine); } + if(cLine->GetParentLine()) cLine->GetParentLine()->RemoveChild(cLine); // Free nodes auto nodeList = cLine->GetNodeList(); for(auto itN = nodeList.begin(), itEndN = nodeList.end(); itN != itEndN; ++itN) { -- cgit From 21ebf63bb59357000f9bb44acde176d4ff169c01 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 9 Mar 2017 15:09:43 -0300 Subject: Sum implemented --- Project/ControlEditor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 3638a42..3b6f8a5 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -103,7 +103,7 @@ ControlEditor::ControlEditor(wxWindow* parent) m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - //m_camera->SetScale(1.2); + // m_camera->SetScale(1.2); } ControlEditor::~ControlEditor() { @@ -282,6 +282,7 @@ void ControlEditor::OnDoubleClick(wxMouseEvent& event) Element* element = *it; if(element->Contains(m_camera->ScreenToWorld(clickPoint))) { element->ShowForm(this, element); + CheckConnections(); auto childList = element->GetChildList(); for(auto itC = childList.begin(), itEndC = childList.end(); itC != itEndC; ++itC) { ConnectionLine* line = static_cast(*itC); @@ -668,3 +669,15 @@ std::vector::iterator ControlEditor::DeleteLineFromList(std::ve if(cLine) delete cLine; return it; } + +void ControlEditor::CheckConnections() +{ + for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) { + ConnectionLine* cLine = *it; + if(cLine->GetType() == ConnectionLine::ELEMENT_ELEMENT) { + if(cLine->GetParentList().size() < 2){ + it = DeleteLineFromList(it); + } + } + } +} -- cgit From 045037ce8f2b106acbe5425245746a2dbed65c26 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 30 Mar 2017 11:10:06 -0300 Subject: Exponencial under implementation --- Project/ControlEditor.cpp | 48 +++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 3b6f8a5..475fdce 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -5,6 +5,9 @@ #include "TransferFunction.h" #include "ConnectionLine.h" #include "Sum.h" +#include "Multiplier.h" +#include "Limiter.h" +#include "RateLimiter.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -61,7 +64,7 @@ void ControlElementButton::OnPaint(wxPaintEvent& event) gc->DrawRectangle(m_borderSize / 2, m_borderSize / 2, m_buttonSize.GetWidth(), m_buttonSize.GetHeight()); } gc->DrawBitmap(gc->CreateBitmapFromImage(m_image), m_imagePosition.x, m_imagePosition.y, m_imageSize.GetWidth(), - m_imageSize.GetHeight()); + m_imageSize.GetHeight()); gc->SetFont(m_font, *wxBLACK); gc->DrawText(m_label, m_labelPosition.x, m_labelPosition.y); delete gc; @@ -96,8 +99,7 @@ void ControlElementButton::OnLeftClickUp(wxMouseEvent& event) event.Skip(); } -ControlEditor::ControlEditor(wxWindow* parent) - : ControlEditorBase(parent) +ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) { BuildControlElementPanel(); m_glContext = new wxGLContext(m_glCanvas); @@ -116,8 +118,8 @@ void ControlEditor::BuildControlElementPanel() wxWrapSizer* wrapSizer = new wxWrapSizer(); m_panelControlElements->SetSizer(wrapSizer); - ControlElementButton* ioButton = new ControlElementButton( - m_panelControlElements, _("In/Out"), wxImage("..\\data\\images\\control\\io.png"), ID_IO); + ControlElementButton* ioButton = new ControlElementButton(m_panelControlElements, _("In/Out"), + wxImage("..\\data\\images\\control\\io.png"), ID_IO); wrapSizer->Add(ioButton, 0, wxALL, 5); ioButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -126,8 +128,8 @@ void ControlEditor::BuildControlElementPanel() wrapSizer->Add(tfButton, 0, wxALL, 5); tfButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* sumButton = new ControlElementButton( - m_panelControlElements, _("Sum"), wxImage("..\\data\\images\\control\\sum.png"), ID_SUM); + ControlElementButton* sumButton = new ControlElementButton(m_panelControlElements, _("Sum"), + wxImage("..\\data\\images\\control\\sum.png"), ID_SUM); wrapSizer->Add(sumButton, 0, wxALL, 5); sumButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -151,8 +153,8 @@ void ControlEditor::BuildControlElementPanel() wrapSizer->Add(multButton, 0, wxALL, 5); multButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* satButton = new ControlElementButton( - m_panelControlElements, _("Saturation"), wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); + ControlElementButton* satButton = new ControlElementButton(m_panelControlElements, _("Saturation"), + wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); wrapSizer->Add(satButton, 0, wxALL, 5); satButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -170,7 +172,7 @@ void ControlEditor::LeftClickDown(wxMouseEvent& event) void ControlEditor::SetViewport() { - glClearColor(1.0, 1.0, 1.0, 1.0); // White background. + glClearColor(1.0, 1.0, 1.0, 1.0); // White background. glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); @@ -213,19 +215,25 @@ void ControlEditor::AddElement(ControlElementButtonID id) wxLogMessage("const"); } break; case ID_LIMITER: { - wxLogMessage("limiter"); + m_mode = MODE_INSERT; + Limiter* limiter = new Limiter(); + m_elementList.push_back(limiter); } break; case ID_GAIN: { wxLogMessage("gain"); } break; case ID_MULT: { - wxLogMessage("mult"); + m_mode = MODE_INSERT; + Multiplier* mult = new Multiplier(); + m_elementList.push_back(mult); } break; case ID_SAT: { wxLogMessage("sat"); } break; case ID_RATELIM: { - wxLogMessage("rateLim"); + m_mode = MODE_INSERT; + RateLimiter* rateLim = new RateLimiter(); + m_elementList.push_back(rateLim); } break; } } @@ -237,8 +245,8 @@ void ControlEditor::OnPaint(wxPaintEvent& event) SetViewport(); // Set GLCanvas scale and translation. - glScaled(m_camera->GetScale(), m_camera->GetScale(), 0.0); // Scale - glTranslated(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y, 0.0); // Translation + glScaled(m_camera->GetScale(), m_camera->GetScale(), 0.0); // Scale + glTranslated(m_camera->GetTranslation().m_x, m_camera->GetTranslation().m_y, 0.0); // Translation for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { ConnectionLine* line = *it; @@ -267,7 +275,7 @@ void ControlEditor::OnPaint(wxPaintEvent& event) glVertex2d(m_selectionRect.m_x + m_selectionRect.m_width, m_selectionRect.m_y); glEnd(); - glFlush(); // Sends all pending information directly to the GPU. + glFlush(); // Sends all pending information directly to the GPU. m_glCanvas->SwapBuffers(); event.Skip(); } @@ -484,7 +492,7 @@ void ControlEditor::OnMouseMotion(wxMouseEvent& event) switch(m_mode) { case MODE_INSERT: { - Element* newElement = *(m_elementList.end() - 1); // Get the last element in the list. + Element* newElement = *(m_elementList.end() - 1); // Get the last element in the list. newElement->Move(m_camera->ScreenToWorld(clickPoint)); redraw = true; } break; @@ -578,11 +586,11 @@ void ControlEditor::OnKeyDown(wxKeyEvent& event) char key = event.GetUnicodeKey(); if(key != WXK_NONE) { switch(key) { - case WXK_DELETE: // Delete selected elements. + case WXK_DELETE: // Delete selected elements. { DeleteSelectedElements(); } break; - case 'R': // Rotate the selected elements. + case 'R': // Rotate the selected elements. { RotateSelectedElements(event.GetModifiers() != wxMOD_SHIFT); } break; @@ -675,7 +683,7 @@ void ControlEditor::CheckConnections() for(auto it = m_connectionList.begin(); it != m_connectionList.end(); ++it) { ConnectionLine* cLine = *it; if(cLine->GetType() == ConnectionLine::ELEMENT_ELEMENT) { - if(cLine->GetParentList().size() < 2){ + if(cLine->GetParentList().size() < 2) { it = DeleteLineFromList(it); } } -- cgit From a684d5c9c9dd131060b5a36d7c7844ae197fcfd1 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Fri, 31 Mar 2017 18:16:05 -0300 Subject: Exponencial implemented --- Project/ControlEditor.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 475fdce..e34c36f 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -8,6 +8,7 @@ #include "Multiplier.h" #include "Limiter.h" #include "RateLimiter.h" +#include "Exponential.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -153,8 +154,8 @@ void ControlEditor::BuildControlElementPanel() wrapSizer->Add(multButton, 0, wxALL, 5); multButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); - ControlElementButton* satButton = new ControlElementButton(m_panelControlElements, _("Saturation"), - wxImage("..\\data\\images\\control\\sat.png"), ID_SAT); + ControlElementButton* satButton = new ControlElementButton(m_panelControlElements, _("Exponential"), + wxImage("..\\data\\images\\control\\sat.png"), ID_EXP); wrapSizer->Add(satButton, 0, wxALL, 5); satButton->Bind(wxEVT_LEFT_DOWN, &ControlEditor::LeftClickDown, this); @@ -227,8 +228,10 @@ void ControlEditor::AddElement(ControlElementButtonID id) Multiplier* mult = new Multiplier(); m_elementList.push_back(mult); } break; - case ID_SAT: { - wxLogMessage("sat"); + case ID_EXP: { + m_mode = MODE_INSERT; + Exponential* exp = new Exponential(); + m_elementList.push_back(exp); } break; case ID_RATELIM: { m_mode = MODE_INSERT; -- cgit From afb0e6e08d3911b7387799f5c465fd59ca26a484 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 1 Apr 2017 17:43:54 -0300 Subject: Constant implemented Missing: gain and io --- Project/ControlEditor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index e34c36f..7a49694 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -9,6 +9,7 @@ #include "Limiter.h" #include "RateLimiter.h" #include "Exponential.h" +#include "Constant.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -106,7 +107,7 @@ ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - // m_camera->SetScale(1.2); + m_camera->SetScale(1.2); } ControlEditor::~ControlEditor() { @@ -213,7 +214,9 @@ void ControlEditor::AddElement(ControlElementButtonID id) m_elementList.push_back(sum); } break; case ID_CONST: { - wxLogMessage("const"); + m_mode = MODE_INSERT; + Constant* constant = new Constant(); + m_elementList.push_back(constant); } break; case ID_LIMITER: { m_mode = MODE_INSERT; -- cgit From 38b3e2decff95f5e29ffb6025ee899d108d22f04 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Tue, 4 Apr 2017 18:10:12 -0300 Subject: Gain implemented Implement io: https://ideone.com/0HDBVd --- Project/ControlEditor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 7a49694..36edb52 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -10,6 +10,7 @@ #include "RateLimiter.h" #include "Exponential.h" #include "Constant.h" +#include "Gain.h" ControlElementButton::ControlElementButton(wxWindow* parent, wxString label, wxImage image, wxWindowID id) : wxWindow(parent, id) @@ -107,7 +108,7 @@ ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - m_camera->SetScale(1.2); + //m_camera->SetScale(1.2); } ControlEditor::~ControlEditor() { @@ -224,7 +225,9 @@ void ControlEditor::AddElement(ControlElementButtonID id) m_elementList.push_back(limiter); } break; case ID_GAIN: { - wxLogMessage("gain"); + m_mode = MODE_INSERT; + Gain* gain = new Gain(); + m_elementList.push_back(gain); } break; case ID_MULT: { m_mode = MODE_INSERT; -- cgit From ed36957d2d06ce9484e39be699bc41b521bdb090 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 6 Apr 2017 17:12:09 -0300 Subject: Io form under implementation --- Project/ControlEditor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 36edb52..6dbf650 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -102,13 +102,15 @@ void ControlElementButton::OnLeftClickUp(wxMouseEvent& event) event.Skip(); } -ControlEditor::ControlEditor(wxWindow* parent) : ControlEditorBase(parent) +ControlEditor::ControlEditor(wxWindow* parent, int ioflags) : ControlEditorBase(parent) { BuildControlElementPanel(); m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); //m_camera->SetScale(1.2); + m_ioFlags = ioflags; + } ControlEditor::~ControlEditor() { @@ -202,7 +204,9 @@ void ControlEditor::AddElement(ControlElementButtonID id) { switch(id) { case ID_IO: { - wxLogMessage("io"); + m_mode = MODE_INSERT; + IOControl* io = new IOControl(m_ioFlags); + m_elementList.push_back(io); } break; case ID_TF: { m_mode = MODE_INSERT; -- cgit From f19803bc64885bcfaef15cfd7a8139c28d3dd506 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 8 Apr 2017 16:31:25 -0300 Subject: Control editor export under implementation File handling --- Project/ControlEditor.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 6dbf650..e9e95f1 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -1,5 +1,6 @@ #include "ControlEditor.h" +#include "FileHanding.h" #include "Camera.h" #include "ControlElement.h" #include "TransferFunction.h" @@ -108,9 +109,8 @@ ControlEditor::ControlEditor(wxWindow* parent, int ioflags) : ControlEditorBase( m_glContext = new wxGLContext(m_glCanvas); m_camera = new Camera(); m_selectionRect = wxRect2DDouble(0, 0, 0, 0); - //m_camera->SetScale(1.2); + // m_camera->SetScale(1.2); m_ioFlags = ioflags; - } ControlEditor::~ControlEditor() { @@ -205,50 +205,51 @@ void ControlEditor::AddElement(ControlElementButtonID id) switch(id) { case ID_IO: { m_mode = MODE_INSERT; - IOControl* io = new IOControl(m_ioFlags); + IOControl* io = new IOControl(m_ioFlags, m_lastElementID); m_elementList.push_back(io); } break; case ID_TF: { m_mode = MODE_INSERT; - TransferFunction* tf = new TransferFunction(); + TransferFunction* tf = new TransferFunction(m_lastElementID); m_elementList.push_back(tf); } break; case ID_SUM: { m_mode = MODE_INSERT; - Sum* sum = new Sum(); + Sum* sum = new Sum(m_lastElementID); m_elementList.push_back(sum); } break; case ID_CONST: { m_mode = MODE_INSERT; - Constant* constant = new Constant(); + Constant* constant = new Constant(m_lastElementID); m_elementList.push_back(constant); } break; case ID_LIMITER: { m_mode = MODE_INSERT; - Limiter* limiter = new Limiter(); + Limiter* limiter = new Limiter(m_lastElementID); m_elementList.push_back(limiter); } break; case ID_GAIN: { m_mode = MODE_INSERT; - Gain* gain = new Gain(); + Gain* gain = new Gain(m_lastElementID); m_elementList.push_back(gain); } break; case ID_MULT: { m_mode = MODE_INSERT; - Multiplier* mult = new Multiplier(); + Multiplier* mult = new Multiplier(m_lastElementID); m_elementList.push_back(mult); } break; case ID_EXP: { m_mode = MODE_INSERT; - Exponential* exp = new Exponential(); + Exponential* exp = new Exponential(m_lastElementID); m_elementList.push_back(exp); } break; case ID_RATELIM: { m_mode = MODE_INSERT; - RateLimiter* rateLim = new RateLimiter(); + RateLimiter* rateLim = new RateLimiter(m_lastElementID); m_elementList.push_back(rateLim); } break; } + m_lastElementID++; } void ControlEditor::OnPaint(wxPaintEvent& event) @@ -333,7 +334,8 @@ void ControlEditor::OnLeftClickDown(wxMouseEvent& event) Node* node = *itN; if(node->Contains(m_camera->ScreenToWorld(clickPoint))) { m_mode = MODE_INSERT_LINE; - ConnectionLine* line = new ConnectionLine(node); + ConnectionLine* line = new ConnectionLine(node, m_lastElementID); + m_lastElementID++; m_connectionList.push_back(line); element->AddChild(line); line->AddParent(element); @@ -586,7 +588,7 @@ void ControlEditor::OnIdle(wxIdleEvent& event) { // Solve wxGLString bug. if(m_firstDraw) { - TransferFunction* tf = new TransferFunction(); + TransferFunction* tf = new TransferFunction(0); m_elementList.push_back(tf); Redraw(); m_elementList.pop_back(); @@ -702,3 +704,14 @@ void ControlEditor::CheckConnections() } } } +void ControlEditor::OnExportClick(wxCommandEvent& event) +{ + FileHanding fileHandling(this); + + wxFileDialog saveFileDialog(this, _("Save CTL file"), "", "", "CTL files (*.ctl)|*.ctl", + wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + if(saveFileDialog.ShowModal() == wxID_CANCEL) return; + + fileHandling.SaveControl(saveFileDialog.GetPath()); + wxFileName fileName(saveFileDialog.GetPath()); +} -- cgit From d2aa79321df798c297334dbcf4e56320b84400ba Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Mon, 10 Apr 2017 19:31:17 -0300 Subject: Control import implementation start --- Project/ControlEditor.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index e9e95f1..4fedfa3 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -584,6 +584,7 @@ void ControlEditor::OnScroll(wxMouseEvent& event) Redraw(); } + void ControlEditor::OnIdle(wxIdleEvent& event) { // Solve wxGLString bug. @@ -596,6 +597,7 @@ void ControlEditor::OnIdle(wxIdleEvent& event) m_firstDraw = false; } } + void ControlEditor::OnKeyDown(wxKeyEvent& event) { char key = event.GetUnicodeKey(); @@ -704,6 +706,7 @@ void ControlEditor::CheckConnections() } } } + void ControlEditor::OnExportClick(wxCommandEvent& event) { FileHanding fileHandling(this); -- cgit From 52931022eb25080e33f2362c3b0bd4361f0cdb0b Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Wed, 12 Apr 2017 18:57:10 -0300 Subject: Open control implementation --- Project/ControlEditor.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 4fedfa3..cb0edf3 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -718,3 +718,19 @@ void ControlEditor::OnExportClick(wxCommandEvent& event) fileHandling.SaveControl(saveFileDialog.GetPath()); wxFileName fileName(saveFileDialog.GetPath()); } + +void ControlEditor::OnImportClick(wxCommandEvent& event) +{ + wxFileDialog openFileDialog(this, _("Open CTL file"), "", "", "CTL files (*.ctl)|*.ctl", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if(openFileDialog.ShowModal() == wxID_CANCEL) return; + + wxFileName fileName(openFileDialog.GetPath()); + + FileHanding fileHandling(this); + if(!fileHandling.OpenControl(fileName)) { + wxMessageDialog msgDialog(this, _("It was not possible to open the selected file."), _("Error"), + wxOK | wxCENTRE | wxICON_ERROR); + msgDialog.ShowModal(); + } +} \ No newline at end of file -- cgit From 0ec05e0cb396a9ef153d29f605d4a0bbeb0dc7c1 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Mon, 17 Apr 2017 20:25:10 -0300 Subject: Connection line import under implementation Parent line not implemented yet --- Project/ControlEditor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index cb0edf3..5d64c5c 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -717,6 +717,7 @@ void ControlEditor::OnExportClick(wxCommandEvent& event) fileHandling.SaveControl(saveFileDialog.GetPath()); wxFileName fileName(saveFileDialog.GetPath()); + event.Skip(); } void ControlEditor::OnImportClick(wxCommandEvent& event) @@ -728,9 +729,20 @@ void ControlEditor::OnImportClick(wxCommandEvent& event) wxFileName fileName(openFileDialog.GetPath()); FileHanding fileHandling(this); - if(!fileHandling.OpenControl(fileName)) { + if(!fileHandling.OpenControl(fileName, m_elementList, m_connectionList)) { wxMessageDialog msgDialog(this, _("It was not possible to open the selected file."), _("Error"), wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } -} \ No newline at end of file + Redraw(); + event.Skip(); +} + +/*void ControlEditor::SetElementsList(std::vector elementList) +{ + m_elementList.clear(); + for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) { + ControlElement* element = *it; + m_elementList.push_back(element); + } +}*/ -- cgit From 341b4a77d2b4c69a99370065af166d92071c9207 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Thu, 20 Apr 2017 18:41:00 -0300 Subject: Export/Import implemented --- Project/ControlEditor.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Project/ControlEditor.cpp') diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index 5d64c5c..e457d0f 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -734,6 +734,21 @@ void ControlEditor::OnImportClick(wxCommandEvent& event) wxOK | wxCENTRE | wxICON_ERROR); msgDialog.ShowModal(); } + + //Get the highest id number + int majorElementID = 0; + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + ControlElement* element = *it; + if(element->GetID() > majorElementID) + majorElementID = element->GetID(); + } + for(auto it = m_connectionList.begin(), itEnd = m_connectionList.end(); it != itEnd; ++it) { + ConnectionLine* line = *it; + if(line->GetID() > majorElementID) + majorElementID = line->GetID(); + } + m_lastElementID = ++majorElementID; + Redraw(); event.Skip(); } -- cgit