2014-09-21 01:04:29 +00:00
|
|
|
#include "basicdrawpane.hpp"
|
|
|
|
|
2014-11-05 16:13:10 +00:00
|
|
|
const wxPen BasicDrawPane::pen[] = {*wxBLACK_PEN, *wxRED_PEN, *wxBLUE_PEN, *wxGREEN_PEN};
|
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);
|
|
|
|
render(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Alternatively, you can use a clientDC to paint on the panel
|
|
|
|
* at any time. Using this generally does not free you from
|
|
|
|
* catching paint events, since it is possible that e.g. the window
|
|
|
|
* manager throws away your drawing when the window comes to the
|
|
|
|
* background, and expects you will redraw it when the window comes
|
|
|
|
* back (by sending a paint event).
|
|
|
|
*
|
|
|
|
* In most cases, this will not be needed at all; simply handling
|
|
|
|
* paint events and calling Refresh() when a refresh is needed
|
|
|
|
* will do the job.
|
|
|
|
*/
|
|
|
|
void BasicDrawPane::paintNow()
|
|
|
|
{
|
|
|
|
wxClientDC dc(this);
|
|
|
|
render(dc);
|
|
|
|
}
|
|
|
|
|
2014-11-09 19:51:18 +00:00
|
|
|
void BasicDrawPane::plotvalue(float values[])
|
2014-11-03 00:29:57 +00:00
|
|
|
{
|
|
|
|
//std::cout << "data:" << value << std::endl;
|
|
|
|
//data.at(xpos) += 0.1;
|
|
|
|
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
|
|
|
}
|
|
|
|
xpos = (xpos+1)%data[0].size();
|
2015-01-15 22:26:29 +00:00
|
|
|
//if(wxGetUTCTimeMillis()-time > 50){
|
2014-11-21 20:34:07 +00:00
|
|
|
Refresh();
|
2015-01-15 22:26:29 +00:00
|
|
|
// time = wxGetUTCTimeMillis();
|
|
|
|
//}
|
2014-11-03 00:29:57 +00:00
|
|
|
//oder
|
|
|
|
//Update();
|
|
|
|
}
|
|
|
|
|
2014-11-09 19:51:18 +00:00
|
|
|
void BasicDrawPane::plotvalue(float value)
|
2014-09-21 01:04:29 +00:00
|
|
|
{
|
2014-10-01 22:01:56 +00:00
|
|
|
//std::cout << "data:" << value << std::endl;
|
2014-09-21 01:04:29 +00:00
|
|
|
//data.at(xpos) += 0.1;
|
2014-11-09 19:51:18 +00:00
|
|
|
data[0].at(xpos) = (float)value;
|
2014-10-31 15:00:08 +00:00
|
|
|
xpos = (xpos+1)%data[0].size();
|
2014-11-21 22:11:32 +00:00
|
|
|
if(wxGetUTCTimeMillis()-time > 50){
|
2014-11-21 20:34:07 +00:00
|
|
|
Refresh();
|
2014-11-21 22:11:32 +00:00
|
|
|
time = wxGetUTCTimeMillis();
|
2014-11-21 20:34:07 +00:00
|
|
|
}
|
2014-09-21 01:04:29 +00:00
|
|
|
//oder
|
|
|
|
//Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here we do the actual rendering. I put it in a separate
|
|
|
|
* method so that it can work no matter what type of DC
|
|
|
|
* (e.g. wxPaintDC or wxClientDC) is used.
|
|
|
|
*/
|
|
|
|
void BasicDrawPane::render(wxDC& dc)
|
|
|
|
{
|
|
|
|
wxCoord w,h;
|
|
|
|
dc.GetSize(&w, &h);
|
|
|
|
|
|
|
|
// ursprung oben links
|
|
|
|
// draw some text
|
|
|
|
|
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
|
2014-11-21 20:34:07 +00:00
|
|
|
// dc.SetPen(*wxBLACK_PEN);
|
|
|
|
// dc.DrawText(wxString::Format(wxT("%i"),diff*50), 40, 60);
|
|
|
|
// dc.DrawLine( 40, 60, 40+50, 60 );
|
2014-09-21 01:04:29 +00:00
|
|
|
|
2014-11-03 00:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-31 15:00:08 +00:00
|
|
|
for (int i = 0; i<channels; i++) {
|
2014-11-03 00:29:57 +00:00
|
|
|
dc.SetPen(pen[i]);
|
|
|
|
x = 0;
|
|
|
|
y = h/2;
|
2014-10-31 15:00:08 +00:00
|
|
|
xstep = w/(data[i].size()-1);
|
|
|
|
for(auto point : data[i]){
|
|
|
|
xold = x;
|
|
|
|
yold = y;
|
|
|
|
y = h/2-point*h/2;
|
|
|
|
dc.DrawLine( xold-xstep, yold, x, y );
|
|
|
|
x += xstep;
|
|
|
|
}
|
2014-09-21 01:04:29 +00:00
|
|
|
}
|
2014-11-03 11:35:53 +00:00
|
|
|
|
|
|
|
//mittellinie
|
|
|
|
dc.SetPen(*wxGREY_PEN);
|
|
|
|
dc.DrawLine( 0, h/2, w, h/2 );
|
2014-09-21 01:04:29 +00:00
|
|
|
// Look at the wxDC docs to learn how to draw other stuff
|
|
|
|
}
|