2015-01-02 21:32:24 -05:00
|
|
|
#include "InteractiveCanvas.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include "AppFrame.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <wx/numformatter.h>
|
|
|
|
|
|
|
|
InteractiveCanvas::InteractiveCanvas(wxWindow *parent, int *attribList) :
|
|
|
|
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
|
2015-01-03 17:07:39 -05:00
|
|
|
wxFULL_REPAINT_ON_RESIZE), parent(parent), shiftDown(false), altDown(false), ctrlDown(false), centerFreq(0), bandwidth(0), lastBandwidth(0), isView(
|
2015-01-02 22:44:09 -05:00
|
|
|
false) {
|
2015-01-03 17:07:39 -05:00
|
|
|
mouseTracker.setTarget(this);
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
InteractiveCanvas::~InteractiveCanvas() {
|
|
|
|
}
|
|
|
|
|
2015-01-04 17:11:20 -05:00
|
|
|
void InteractiveCanvas::setView(long long center_freq_in, int bandwidth_in) {
|
2015-01-02 21:32:24 -05:00
|
|
|
isView = true;
|
2015-01-03 17:07:39 -05:00
|
|
|
centerFreq = center_freq_in;
|
2015-01-02 21:32:24 -05:00
|
|
|
bandwidth = bandwidth_in;
|
2015-01-03 17:07:39 -05:00
|
|
|
lastBandwidth = 0;
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::disableView() {
|
2015-01-02 21:32:24 -05:00
|
|
|
isView = false;
|
2015-01-03 17:07:39 -05:00
|
|
|
centerFreq = wxGetApp().getFrequency();
|
2015-01-11 17:08:16 -05:00
|
|
|
bandwidth = wxGetApp().getSampleRate();
|
2015-01-03 17:07:39 -05:00
|
|
|
lastBandwidth = 0;
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-03-29 20:24:00 -04:00
|
|
|
bool InteractiveCanvas::getViewState() {
|
|
|
|
return isView;
|
|
|
|
}
|
|
|
|
|
2015-01-04 17:11:20 -05:00
|
|
|
long long InteractiveCanvas::getFrequencyAt(float x) {
|
|
|
|
long long iqCenterFreq = getCenterFrequency();
|
|
|
|
long long iqBandwidth = getBandwidth();
|
|
|
|
long long freq = iqCenterFreq - (long long)(0.5 * (long double) iqBandwidth) + ((long double) x * (long double) iqBandwidth);
|
2015-01-02 21:32:24 -05:00
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
2015-01-04 17:11:20 -05:00
|
|
|
void InteractiveCanvas::setCenterFrequency(long long center_freq_in) {
|
2015-01-03 17:07:39 -05:00
|
|
|
centerFreq = center_freq_in;
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-01-04 17:11:20 -05:00
|
|
|
long long InteractiveCanvas::getCenterFrequency() {
|
2015-01-02 21:32:24 -05:00
|
|
|
if (isView) {
|
2015-01-03 17:07:39 -05:00
|
|
|
return centerFreq;
|
2015-01-02 21:32:24 -05:00
|
|
|
} else {
|
2015-01-04 17:11:20 -05:00
|
|
|
return wxGetApp().getFrequency();
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::setBandwidth(unsigned int bandwidth_in) {
|
2015-01-02 21:32:24 -05:00
|
|
|
bandwidth = bandwidth_in;
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
unsigned int InteractiveCanvas::getBandwidth() {
|
2015-01-02 21:32:24 -05:00
|
|
|
if (isView) {
|
|
|
|
return bandwidth;
|
|
|
|
} else {
|
2015-01-11 17:08:16 -05:00
|
|
|
return wxGetApp().getSampleRate();
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:51:22 -04:00
|
|
|
MouseTracker *InteractiveCanvas::getMouseTracker() {
|
|
|
|
return &mouseTracker;
|
|
|
|
}
|
|
|
|
|
2015-01-02 21:32:24 -05:00
|
|
|
void InteractiveCanvas::OnKeyUp(wxKeyEvent& event) {
|
|
|
|
shiftDown = event.ShiftDown();
|
|
|
|
altDown = event.AltDown();
|
|
|
|
ctrlDown = event.ControlDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InteractiveCanvas::OnKeyDown(wxKeyEvent& event) {
|
|
|
|
float angle = 5.0;
|
|
|
|
|
|
|
|
shiftDown = event.ShiftDown();
|
|
|
|
altDown = event.AltDown();
|
|
|
|
ctrlDown = event.ControlDown();
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseMoved(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseMoved(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
|
|
|
|
shiftDown = event.ShiftDown();
|
|
|
|
altDown = event.AltDown();
|
|
|
|
ctrlDown = event.ControlDown();
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseDown(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseDown(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
|
|
|
|
shiftDown = event.ShiftDown();
|
|
|
|
altDown = event.AltDown();
|
|
|
|
ctrlDown = event.ControlDown();
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseWheelMoved(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseReleased(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseReleased(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
|
|
|
|
shiftDown = event.ShiftDown();
|
|
|
|
altDown = event.AltDown();
|
|
|
|
ctrlDown = event.ControlDown();
|
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseLeftWindow(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
void InteractiveCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseEnterWindow(event);
|
2015-01-02 21:32:24 -05:00
|
|
|
}
|
|
|
|
|
2015-01-02 22:44:09 -05:00
|
|
|
void InteractiveCanvas::setStatusText(std::string statusText) {
|
|
|
|
((wxFrame*) parent)->GetStatusBar()->SetStatusText(statusText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InteractiveCanvas::setStatusText(std::string statusText, int value) {
|
|
|
|
((wxFrame*) parent)->GetStatusBar()->SetStatusText(
|
|
|
|
wxString::Format(statusText.c_str(), wxNumberFormatter::ToString((long) value, wxNumberFormatter::Style_WithThousandsSep)));
|
|
|
|
}
|
2015-01-03 17:07:39 -05:00
|
|
|
|
|
|
|
void InteractiveCanvas::OnMouseRightDown(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseRightDown(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InteractiveCanvas::OnMouseRightReleased(wxMouseEvent& event) {
|
|
|
|
mouseTracker.OnMouseRightReleased(event);
|
|
|
|
}
|