2014-09-21 01:04:29 +00:00
|
|
|
#include "basicdrawpane.hpp"
|
2015-04-06 09:53:34 +00:00
|
|
|
#include <wx/graphics.h>
|
2014-09-21 01:04:29 +00:00
|
|
|
|
2015-07-02 17:31:10 +00:00
|
|
|
const wxPen BasicDrawPane::pen[] = {
|
|
|
|
*wxBLACK_PEN,
|
|
|
|
*wxRED_PEN,
|
|
|
|
*wxBLUE_PEN,
|
|
|
|
*wxGREEN_PEN,
|
|
|
|
wxPen(wxColour(255, 128, 0)),
|
|
|
|
wxPen(wxColour(128, 128, 64)),
|
|
|
|
wxPen(wxColour(128, 64, 128)),
|
|
|
|
wxPen(wxColour(64, 128, 128))
|
|
|
|
};
|
2014-11-03 11:35:53 +00:00
|
|
|
|
2014-10-31 15:00:08 +00:00
|
|
|
BasicDrawPane::BasicDrawPane(wxFrame* parent, int ch) : wxPanel(parent){
|
2014-11-21 22:11:32 +00:00
|
|
|
time = wxGetUTCTimeMillis();
|
2014-09-21 01:04:29 +00:00
|
|
|
Bind(wxEVT_PAINT, &BasicDrawPane::paintEvent, this);
|
|
|
|
xpos = 0;
|
2014-10-31 15:00:08 +00:00
|
|
|
channels = ch;
|
2014-11-03 11:35:53 +00:00
|
|
|
|
2014-10-31 15:00:08 +00:00
|
|
|
for (int i = 0; i<channels; i++) {
|
|
|
|
data.push_back(std::vector<float>());
|
2014-11-04 14:36:26 +00:00
|
|
|
for (int j = 0; j<1024; j++) {
|
2014-10-31 15:00:08 +00:00
|
|
|
data[i].push_back(0);
|
|
|
|
}
|
2014-09-21 01:04:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-03 11:35:53 +00:00
|
|
|
void BasicDrawPane::Clear(){
|
|
|
|
for (int i = 0; i<channels; i++) {
|
|
|
|
for (auto &d : data[i]){
|
|
|
|
d = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xpos = 0;
|
2014-11-05 16:13:10 +00:00
|
|
|
Refresh();
|
2014-11-03 11:35:53 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 01:04:29 +00:00
|
|
|
/*
|
|
|
|
* Called by the system of by wxWidgets when the panel needs
|
|
|
|
* to be redrawn. You can also trigger this call by
|
|
|
|
* calling Refresh()/Update().
|
|
|
|
*/
|
|
|
|
|
|
|
|
void BasicDrawPane::paintEvent(wxPaintEvent & evt)
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
2015-04-06 09:53:34 +00:00
|
|
|
wxCoord w,h;
|
|
|
|
dc.GetSize(&w, &h);
|
|
|
|
wxGraphicsContext *gc = wxGraphicsContext::Create( dc );
|
|
|
|
if (gc)
|
|
|
|
{
|
|
|
|
for (int i = 0; i<channels; i++) {
|
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
gc->SetPen(pen[i]);
|
|
|
|
x = 0;
|
|
|
|
y = h/2;
|
2015-11-27 00:25:46 +00:00
|
|
|
xstep = (double)w/(double)(data[i].size()-1);
|
2015-04-06 09:53:34 +00:00
|
|
|
path.MoveToPoint(x, y);
|
|
|
|
for(auto point : data[i]){
|
|
|
|
y = h/2-point*h/2;
|
|
|
|
path.AddLineToPoint(x, y);
|
|
|
|
x += xstep;
|
|
|
|
}
|
|
|
|
gc->StrokePath(path);
|
|
|
|
}
|
2015-06-04 22:29:46 +00:00
|
|
|
|
2015-04-06 09:53:34 +00:00
|
|
|
//center line
|
|
|
|
wxGraphicsPath path = gc->CreatePath();
|
|
|
|
gc->SetPen(*wxGREY_PEN);
|
|
|
|
path.MoveToPoint(0, h/2);
|
|
|
|
path.AddLineToPoint(w, h/2);
|
|
|
|
path.CloseSubpath();
|
|
|
|
gc->StrokePath(path);
|
|
|
|
delete gc;
|
|
|
|
}
|
2014-09-21 01:04:29 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 19:51:18 +00:00
|
|
|
void BasicDrawPane::plotvalue(float values[])
|
2014-11-03 00:29:57 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i<channels; i++) {
|
2014-11-09 19:51:18 +00:00
|
|
|
data[i].at(xpos) = (float)values[i];
|
2014-11-03 00:29:57 +00:00
|
|
|
}
|
2015-11-27 00:25:46 +00:00
|
|
|
xpos = ((int)xpos+1)%data[0].size();
|
|
|
|
Refresh();
|
2014-11-03 00:29:57 +00:00
|
|
|
}
|