From: wittend99 Date: Mon, 17 Sep 2012 18:16:46 +0000 (+0000) Subject: git-svn-id: https://svn.code.sf.net/p/freetel/code@716 01035d8c-6547-0410-b346-abe4f9... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=76e277972febeccce80192bd224c2cb619e13803;p=freetel-svn-tracking.git git-svn-id: https://svn.code.sf.net/p/freetel/code@716 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/fdmdv2/build/fdmdv2.mk b/fdmdv2/build/fdmdv2.mk index 376a9c67..0f10b717 100644 --- a/fdmdv2/build/fdmdv2.mk +++ b/fdmdv2/build/fdmdv2.mk @@ -2,18 +2,18 @@ ## Auto Generated makefile by CodeLite IDE ## any manual changes will be erased ## -## Release +## Debug ProjectName :=fdmdv2 -ConfigurationName :=Release +ConfigurationName :=Debug WorkspacePath := "C:\bin\Projects\Radio\fdmdv2\build" ProjectPath := "C:\bin\Projects\Radio\fdmdv2\build" -IntermediateDirectory :=./Release +IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=OFA-Staff -Date :=9/14/2012 +Date :=9/17/2012 CodeLitePath :="C:\bin\CodeLite" LinkerName :=g++ SharedObjectLinkerName :=g++ -shared -fPIC @@ -35,7 +35,7 @@ PreprocessOnlySwitch :=-E ObjectsFileList :="C:\bin\Projects\Radio\fdmdv2\build\fdmdv2.txt" PCHCompileFlags := MakeDirCommand :=makedir -LinkOptions := -mwindows -s $(shell wx-config --debug=no --libs --unicode=yes) +LinkOptions := -mwindows $(shell wx-config --debug=yes --libs --unicode=yes) IncludePath := $(IncludeSwitch). $(IncludeSwitch)/bin/MinGW/msys/1.0/local/include $(IncludeSwitch)../../codec2-dev/src $(IncludeSwitch)../3rdparty/portaudio/include $(IncludeSwitch)../3rdparty/portaudio/bindings/cpp/include $(IncludeSwitch)../3rdparty/libsndfile/include $(IncludeSwitch)../3rdparty/libsamplerate-0.1.8/src IncludePCH := RcIncludePath := @@ -50,8 +50,8 @@ LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)/bin/MinGW/m AR := ar rcus CXX := g++ CC := gcc -CXXFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"674\" $(Preprocessors) -CFLAGS := -O2 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=no) -DSVN_REVISION=\"674\" $(Preprocessors) +CXXFLAGS := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) -DSVN_REVISION=\"674\" $(Preprocessors) +CFLAGS := -g -O0 -Wall $(shell wx-config --cxxflags --unicode=yes --debug=yes) -DSVN_REVISION=\"674\" $(Preprocessors) ## @@ -78,7 +78,7 @@ $(OutputFile): $(IntermediateDirectory)/.d $(Objects) $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) $(IntermediateDirectory)/.d: - @$(MakeDirCommand) "./Release" + @$(MakeDirCommand) "./Debug" PreBuild: @@ -226,6 +226,6 @@ clean: $(RM) $(IntermediateDirectory)/src_fdmdv2_plot_scalar$(PreprocessSuffix) $(RM) $(OutputFile) $(RM) $(OutputFile).exe - $(RM) "C:\bin\Projects\Radio\fdmdv2\build\.build-release\fdmdv2" + $(RM) "C:\bin\Projects\Radio\fdmdv2\build\.build-debug\fdmdv2" diff --git a/fdmdv2/build/fdmdv2.txt b/fdmdv2/build/fdmdv2.txt index 444adc7e..b4a88d46 100644 --- a/fdmdv2/build/fdmdv2.txt +++ b/fdmdv2/build/fdmdv2.txt @@ -1 +1 @@ -./Release/src_dlg_about.o ./Release/src_dlg_audio.o ./Release/src_dlg_comports.o ./Release/src_dlg_options.o ./Release/src_fdmdv2_main.o ./Release/src_fdmdv2_plot.o ./Release/src_topFrame.o ./Release/src_fdmdv2_plot_scatter.o ./Release/src_fdmdv2_plot_waterfall.o ./Release/src_fdmdv2_plot_spectrum.o ./Release/src_fdmdv2_pa_wrapper.o ./Release/src_fdmdv2_plot_scalar.o +./Debug/src_dlg_about.o ./Debug/src_dlg_audio.o ./Debug/src_dlg_comports.o ./Debug/src_dlg_options.o ./Debug/src_fdmdv2_main.o ./Debug/src_fdmdv2_plot.o ./Debug/src_topFrame.o ./Debug/src_fdmdv2_plot_scatter.o ./Debug/src_fdmdv2_plot_waterfall.o ./Debug/src_fdmdv2_plot_spectrum.o ./Debug/src_fdmdv2_pa_wrapper.o ./Debug/src_fdmdv2_plot_scalar.o diff --git a/fdmdv2/build/fdmdv2.workspace b/fdmdv2/build/fdmdv2.workspace index e70810b8..39870050 100644 --- a/fdmdv2/build/fdmdv2.workspace +++ b/fdmdv2/build/fdmdv2.workspace @@ -1,12 +1,15 @@ + - + + + diff --git a/fdmdv2/build/fdmdv2_wsp.mk b/fdmdv2/build/fdmdv2_wsp.mk index 59fb53ea..4ea617a2 100644 --- a/fdmdv2/build/fdmdv2_wsp.mk +++ b/fdmdv2/build/fdmdv2_wsp.mk @@ -1,8 +1,8 @@ .PHONY: clean All All: - @echo ----------Building project:[ fdmdv2 - Release ]---------- + @echo ----------Building project:[ fdmdv2 - Debug ]---------- @"$(MAKE)" -f "fdmdv2.mk" clean: - @echo ----------Cleaning project:[ fdmdv2 - Release ]---------- + @echo ----------Cleaning project:[ fdmdv2 - Debug ]---------- @"$(MAKE)" -f "fdmdv2.mk" clean diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index ad98b1c2..0bbf15a9 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -91,16 +91,16 @@ bool MainApp::loadConfig() //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class MainFrame(wxFrame* pa->ent) : TopFrame(parent) -// -// @class $(Name) -// @author $(User) -// @date $(Date) -// @file $(CurrentFileName).$(CurrentFileExt) -// @brief -// //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) { + /* + // @class $(Name) + // @author $(User) + // @date $(Date) + // @file $(CurrentFileName).$(CurrentFileExt) + // @brief + */ // m_radioRunning = false; m_sound = NULL; m_zoom = 1.; @@ -127,8 +127,18 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) m_panelDefaultA = new PlotPanel((wxFrame*) m_auiNbookCtrl ); m_auiNbookCtrl->AddPage(m_panelDefaultA, _("Test A"), true, wxNullBitmap ); #ifdef USE_TIMER -// this->Connect(wxEVT_TIMER, MainFrame::OnTimer); //, ID_TIMER_WATERFALL); - Bind(wxEVT_TIMER, &MainFrame::OnTimer, this); // ID_MY_WINDOW); + m_rxPa = new PortAudioWrap(); + double f = 0.0; + for(int i = 0; i < FDMDV_NSPEC; i++) + { +// m_rxPa->m_av_mag[i] = sin(i) * 100.0; + f = ((double)i / M_PI); + f = sin(f); + f = 100 * f; +// f = f - 50; + m_rxPa->m_av_mag[i] = f; + } + Bind(wxEVT_TIMER, &MainFrame::OnTimer, this); // ID_MY_WINDOW); m_plotTimer.SetOwner(this, ID_TIMER_WATERFALL); m_plotTimer.Start(500, wxTIMER_CONTINUOUS); #endif @@ -149,13 +159,20 @@ MainFrame::~MainFrame() } #ifdef USE_TIMER +//static int cnt = 3; + //---------------------------------------------------------------- // OnTimer() //---------------------------------------------------------------- void MainFrame::OnTimer(wxTimerEvent &evt) { +// cnt--; m_panelWaterfall->m_newdata = true; m_panelWaterfall->Refresh(); + m_panelSpectrum->m_newdata = true; + m_panelSpectrum->Refresh(); +// m_panelDefaultA->m_newdata = true; +// m_panelDefaultA->Refresh(); } #endif diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index a6e03879..7c3543c0 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -12,6 +12,7 @@ #include +#include "wx/rawbmp.h" #include "wx/file.h" #include "wx/config.h" #include "wx/filename.h" diff --git a/fdmdv2/src/fdmdv2_plot.cpp b/fdmdv2/src/fdmdv2_plot.cpp index 8f91f828..d66c76a0 100644 --- a/fdmdv2/src/fdmdv2_plot.cpp +++ b/fdmdv2/src/fdmdv2_plot.cpp @@ -41,8 +41,11 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent) { m_pNoteBook = (wxAuiNotebook *) parent; m_pTopFrame = (MainFrame *)m_pNoteBook->GetParent(); -// m_bmp = new wxBitmap(MAX_BMP_X, MAX_BMP_Y, wxBITMAP_SCREEN_DEPTH); m_zoomFactor = 1.0; + m_pBmp = NULL; + m_pPix = NULL; + m_firstPass = true; + m_line_color = 0; m_newdata = false; m_clip = false; m_use_bitmap = true; @@ -53,19 +56,6 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent) m_penSolid = wxPen(wxColor(0x00, 0x00, 0x00), 1, wxPENSTYLE_SOLID); SetBackgroundStyle(wxBG_STYLE_PAINT); SetLabelSize(10.0); -/* - wxNativePixelData m_pBmp(*m_bmp); - if(!m_pBmp) - { - // ... raw access to bitmap data unavailable, do something else ... - return; - } - if(m_pBmp.GetWidth() < 20 || m_pBmp.GetHeight() < 20) - { - // ... complain: the bitmap it too small ... - return; - } -*/ } //------------------------------------------------------------------------- @@ -73,9 +63,9 @@ PlotPanel::PlotPanel(wxFrame* parent) : wxPanel(parent) //------------------------------------------------------------------------- PlotPanel::~PlotPanel() { - if(!m_bmp->IsNull()) + if(!m_pBmp->IsNull()) { - delete m_bmp; + delete m_pBmp; } } @@ -120,9 +110,26 @@ void PlotPanel::OnSize(wxSizeEvent& event) m_rCtrl = GetClientRect(); if(m_use_bitmap) { - m_bmp = new wxBitmap(m_rCtrl.GetWidth(), m_rCtrl.GetHeight(), wxBITMAP_SCREEN_DEPTH); + if(!m_oImage.IsOk()) + { + m_oImage.Create(m_rCtrl.GetWidth(), m_rCtrl.GetHeight(), true); + } + else + { + m_oImage.Rescale(m_rCtrl.GetWidth(), m_rCtrl.GetHeight()); + } + m_pBmp = new wxBitmap(m_oImage, wxBITMAP_SCREEN_DEPTH); +/* + if(m_oImage.IsOk()) + { + m_oImage.Destroy(); + } + m_oImage.Create(m_rCtrl.GetWidth(), m_rCtrl.GetHeight(), true); + m_pBmp = new wxBitmap(m_oImage, wxBITMAP_SCREEN_DEPTH); + m_oImage.Rescale(m_rCtrl.GetWidth(), m_rCtrl.GetHeight()); +*/ m_firstPass = true; - this->Refresh(); +// this->Refresh(); } } @@ -180,70 +187,84 @@ double PlotPanel::GetZoomFactor(double zf) return m_zoomFactor; } +//------------------------------------------------------------------------- +// draw() +//------------------------------------------------------------------------- +void PlotPanel::draw(wxAutoBufferedPaintDC& pDC) +{ + wxMemoryDC m_mDC; + m_mDC.SelectObject(*m_pBmp); + m_rCtrl = GetClientRect(); + m_rGrid = m_rCtrl; + + m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); + m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); + + pDC.Clear(); + m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight()); + if(m_firstPass) + { + m_firstPass = false; + m_mDC.FloodFill(0, 0, VERY_LTGREY_COLOR); + + // Draw a filled rectangle with aborder + wxBrush ltGraphBkgBrush = wxBrush(DARK_BLUE_COLOR); + m_mDC.SetBrush(ltGraphBkgBrush); + m_mDC.SetPen(wxPen(BLACK_COLOR, 0)); + m_mDC.DrawRectangle(m_rPlot); + } + if(m_newdata) + { + m_newdata = false; + int t = m_rPlot.GetTop(); + int l = m_rPlot.GetLeft(); + int r = m_rPlot.GetRight(); + int h = m_rPlot.GetHeight(); + int w = m_rPlot.GetWidth(); + pDC.Blit(l, t, w, h, &m_mDC, l, t); + } + drawGraticule(pDC); + m_mDC.SetBrush(wxNullBrush); + m_mDC.SelectObject(wxNullBitmap); +} + //------------------------------------------------------------------------- // drawGraticule() //------------------------------------------------------------------------- -void PlotPanel::drawGraticule(wxAutoBufferedPaintDC& pdc) +void PlotPanel::drawGraticule(wxAutoBufferedPaintDC& pDC) { int p; char buf[15]; wxString s; // Vertical gridlines - pdc.SetPen(m_penShortDash); - for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rCtrl.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT) + pDC.SetPen(m_penShortDash); + for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rGrid.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT) { - pdc.DrawLine(p, (m_rGrid.GetHeight() + PLOT_BORDER), p, PLOT_BORDER); + pDC.DrawLine(p, (m_rGrid.GetHeight() + PLOT_BORDER), p, PLOT_BORDER); } // Horizontal gridlines - pdc.SetPen(m_penDotDash); + pDC.SetPen(m_penDotDash); for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) { - pdc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (p + PLOT_BORDER), (m_rCtrl.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (p + PLOT_BORDER)); + pDC.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (p + PLOT_BORDER), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (p + PLOT_BORDER)); } // Label the X-Axis - pdc.SetPen(wxPen(GREY_COLOR, 1)); - for(p = GRID_INCREMENT; p < (m_rCtrl.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT) + pDC.SetPen(wxPen(GREY_COLOR, 1)); + for(p = GRID_INCREMENT; p < (m_rGrid.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT) { sprintf(buf, "%1.1f Hz",(double)(p / 10)); - pdc.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/2); + pDC.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/2); } // Label the Y-Axis //for(p = GRID_INCREMENT; p < (h - YBOTTOM_OFFSET); p += GRID_INCREMENT) for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) { sprintf(buf, "%1.0f", (double)((m_rGrid.GetHeight() - p) * -10)); - pdc.DrawText(buf, XLEFT_TEXT_OFFSET, p); + pDC.DrawText(buf, XLEFT_TEXT_OFFSET, p); } } -//------------------------------------------------------------------------- -// draw() -//------------------------------------------------------------------------- -void PlotPanel::draw(wxAutoBufferedPaintDC& pdc) -{ -// wxAutoBufferedPaintDC dc(this); -// wxMemoryDC memdc(&m_bmp); - - m_rCtrl = GetClientRect(); - m_rGrid = m_rCtrl; - - m_rCtrl.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); - m_rCtrl.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); - - //m_h = m_rCtrl.GetHeight(); - //m_w = m_rCtrl.GetWidth(); - - pdc.Clear(); - - // Draw a filled rectangle with aborder - wxBrush ltBlueBrush = wxBrush(LIGHT_BLUE_COLOR); - pdc.SetBrush(ltBlueBrush); - pdc.SetPen(wxPen(BLACK_COLOR, 1)); - pdc.DrawRectangle(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rCtrl.GetWidth(), m_rCtrl.GetHeight()); - drawGraticule(pdc); -} - //------------------------------------------------------------------------- // paintEvent() // diff --git a/fdmdv2/src/fdmdv2_plot.h b/fdmdv2/src/fdmdv2_plot.h index f1e655c3..55a28782 100644 --- a/fdmdv2/src/fdmdv2_plot.h +++ b/fdmdv2/src/fdmdv2_plot.h @@ -19,6 +19,9 @@ #define MAX_ZOOM 7 #define MAX_BMP_X (400 * MAX_ZOOM) #define MAX_BMP_Y (400 * MAX_ZOOM) +#define DATA_LINE_HEIGHT 10 +#define TEXT_BASELINE_OFFSET_Y -5 + #define wxUSE_FILEDLG 1 #define wxUSE_LIBPNG 1 @@ -41,6 +44,7 @@ #define VERY_LTGREY_COLOR wxColor(0xF8, 0xF8, 0xF8) #define WHITE_COLOR wxColor(0xFF, 0xFF, 0xFF) +#define DARK_BLUE_COLOR wxColor(0x00, 0x00, 0x80) #define BLUE_COLOR wxColor(0x00, 0x00, 0xFF) #define LIGHT_BLUE_COLOR wxColor(0x80, 0x80, 0xFF) @@ -58,22 +62,6 @@ #define LIGHT_YELLOW_COLOR wxColor(0xFF, 0xFF, 0xB5) #define DARK_YELLOW_COLOR wxColor(0xFF, 0xFF, 0x08) - -/* - wxNullBrush - wxBLACK_BRUSH - wxBLUE_BRUSH - wxCYAN_BRUSH - wxGREEN_BRUSH - wxYELLOW_BRUSH - wxGREY_BRUSH - wxLIGHT_GREY_BRUSH - wxMEDIUM_GREY_BRUSH - wxRED_BRUSH - wxTRANSPARENT_BRUSH - wxWHITE_BRUSH -*/ - class MainFrame; //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= @@ -103,8 +91,9 @@ class PlotPanel : public wxPanel double m_label_size; wxSize m_Bufsz; bool m_newdata; - wxBitmap *m_bmp; - wxNativePixelData *m_pBmp; + wxImage m_oImage; + wxBitmap *m_pBmp; + wxNativePixelData *m_pPix; // some useful events void OnMouseMove(wxMouseEvent& event); @@ -129,8 +118,6 @@ class PlotPanel : public wxPanel protected: int m_x; int m_y; -// int m_w; -// int m_h; int m_left; int m_top; int m_prev_w; @@ -143,6 +130,8 @@ class PlotPanel : public wxPanel bool m_mouseDown; bool m_firstPass; double m_zoomFactor; + int m_greyscale; + int m_line_color; DECLARE_EVENT_TABLE() }; #endif //__FDMDV2_PLOT__ diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.cpp b/fdmdv2/src/fdmdv2_plot_spectrum.cpp index 4c643713..d8717cce 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.cpp +++ b/fdmdv2/src/fdmdv2_plot_spectrum.cpp @@ -41,13 +41,119 @@ END_EVENT_TABLE() //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= // Class PlotSpectrum +// +// @class $(Name) +// @author $(User) +// @date $(Date) +// @file $(CurrentFileName).$(CurrentFileExt) +// @brief +// //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= PlotSpectrum::PlotSpectrum(wxFrame* parent): PlotPanel(parent) { + m_greyscale = 0; + m_Bufsz = GetMaxClientSize(); + m_newdata = false; + m_firstPass = true; + m_line_color = 0; SetLabelSize(10.0); } -#define TEXT_BASELINE_OFFSET_Y -5 +//---------------------------------------------------------------- +// ~PlotSpectrum() +//---------------------------------------------------------------- +PlotSpectrum::~PlotSpectrum() +{ +} + +//---------------------------------------------------------------- +// draw() +//---------------------------------------------------------------- +void PlotSpectrum::draw(wxAutoBufferedPaintDC& pDC) +{ + wxMemoryDC m_mDC; + m_mDC.SelectObject(*m_pBmp); + m_rCtrl = GetClientRect(); + m_rGrid = m_rCtrl; + + m_rGrid = m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); + m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); + + pDC.Clear(); + m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight()); + if(m_firstPass) + { + m_firstPass = false; + m_mDC.Clear(); + m_mDC.FloodFill(0, 0, VERY_LTGREY_COLOR); + + // Draw a filled rectangle with aborder +// wxBrush ltGraphBkgBrush = wxBrush(LIGHT_YELLOW_COLOR); + wxBrush ltGraphBkgBrush = wxBrush(DARK_GREY_COLOR); + m_mDC.SetBrush(ltGraphBkgBrush); + m_mDC.SetPen(wxPen(BLACK_COLOR, 0)); + m_mDC.DrawRectangle(m_rPlot); + } + if(m_newdata) + { + m_newdata = false; +// plotPixelData(dc); +#ifdef USE_TIMER + int t = m_rPlot.GetTop(); + int l = m_rPlot.GetLeft(); + int h = m_rPlot.GetHeight(); + int w = m_rPlot.GetWidth(); + //double stride = w / FDMDV_NSPEC; + + wxPen pen; + pen.SetColour(DARK_GREEN_COLOR); + pen.SetWidth(1); + m_mDC.SetPen(pen); + + float *pData = m_pTopFrame->m_rxPa->m_av_mag; + for(int x = 1; x < w; x++) + { +// m_mDC.DrawPoint(x, (int)pData[x]); + m_mDC.DrawLine((x - 1), (int)pData[(x - 1)] + (h / 2), x, (int)pData[x] + (h / 2)); + } + pDC.Blit(l, t, w, h, &m_mDC, l, t); +#endif + drawGraticule(pDC); + } + m_mDC.SetBrush(wxNullBrush); + m_mDC.SelectObject(wxNullBitmap); +} + +//------------------------------------------------------------------------- +// drawData() +//------------------------------------------------------------------------- +void PlotSpectrum::drawData() //wxMemoryDC& pDC) +{ + wxNativePixelData dPix = wxNativePixelData(*m_pBmp, m_rCtrl); + m_pPix = &dPix; + if(m_pPix == NULL) + { + return; + } + wxNativePixelData::Iterator p(*m_pPix); + + int w = m_rPlot.GetWidth(); + int h = m_rPlot.GetHeight(); + p.Offset(*m_pPix, XLEFT_OFFSET + 3, h - (DATA_LINE_HEIGHT - 2)); +// for(int y = 0; y < DATA_LINE_HEIGHT; ++y) +// { + wxNativePixelData::Iterator rowStart = p; + for(int x = 0; x < (w - 1); ++x, ++p) + { + p.OffsetX(*m_pPix, m_pTopFrame->m_rxPa->m_av_mag[x]); + p.Red() = 0x00; // m_pTopFrame->m_rxPa->m_av_mag[x]; + p.Green() = 0xFF; + p.Blue() = 0x00; // m_pTopFrame->m_rxPa->m_av_mag[x]; + } + p = rowStart; +// p.OffsetY(*m_pPix, 1); +// } +} //------------------------------------------------------------------------- // drawGraticule() @@ -61,28 +167,28 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) // Vertical gridlines dc.SetPen(m_penShortDash); - for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rCtrl.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT) + for(p = (PLOT_BORDER + XLEFT_OFFSET + GRID_INCREMENT); p < ((m_rGrid.GetWidth() - XLEFT_OFFSET) + GRID_INCREMENT); p += GRID_INCREMENT) { - dc.DrawLine(p, (m_rCtrl.GetHeight() + PLOT_BORDER), p, PLOT_BORDER); + dc.DrawLine(p, (m_rGrid.GetHeight() + PLOT_BORDER), p, PLOT_BORDER); } - int y_zero = (m_rCtrl.GetHeight() - m_top) / 2 ; + int y_zero = (m_rGrid.GetHeight() - m_top) / 2 ; dc.SetPen(m_penSolid); - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y_zero, (m_rCtrl.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y_zero); + dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, y_zero, (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), y_zero); sprintf(buf, "%6.0f", 0.0); dc.DrawText(buf, XLEFT_TEXT_OFFSET, y_zero + TEXT_BASELINE_OFFSET_Y); // Horizontal gridlines dc.SetPen(m_penDotDash); - for(p = 0; (y_zero + p) < m_rCtrl.GetHeight() ; p += GRID_INCREMENT) + for(p = 0; (y_zero + p) < m_rGrid.GetHeight() ; p += GRID_INCREMENT) { if(p > 0) { - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero + p), (m_rCtrl.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero + p)); + dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero + p), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero + p)); sprintf(buf, "%6.0f", (double)(p) * -10); dc.DrawText(buf, XLEFT_TEXT_OFFSET, (y_zero + p + TEXT_BASELINE_OFFSET_Y)); - dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero - p), (m_rCtrl.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero - p)); + dc.DrawLine(PLOT_BORDER + XLEFT_OFFSET, (y_zero - p), (m_rGrid.GetWidth() + PLOT_BORDER + XLEFT_OFFSET), (y_zero - p)); sprintf(buf, "%6.0f", (double)(p) * 10); dc.DrawText(buf, XLEFT_TEXT_OFFSET, (y_zero - p + TEXT_BASELINE_OFFSET_Y)); } @@ -97,111 +203,6 @@ void PlotSpectrum::drawGraticule(wxAutoBufferedPaintDC& dc) } } -//---------------------------------------------------------------- -// draw() -//---------------------------------------------------------------- -void PlotSpectrum::draw(wxAutoBufferedPaintDC& dc) -{ -/* - float x_px_per_point = 0.0; - float y_px_per_dB = 0.0; - int i; - int x1; - int y1; - int x2; - int y2; - float mag1, mag2; - char label[20]; - float px_per_hz; -*/ - m_rCtrl = GetClientRect(); - m_rGrid = m_rCtrl; - - m_rGrid.Deflate(PLOT_BORDER + (XLEFT_OFFSET/2), (PLOT_BORDER + (YBOTTOM_OFFSET/2))); - m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); - -// m_rGrid.Deflate(PLOT_BORDER, (PLOT_BORDER + (YBOTTOM_OFFSET/2))); -// m_rGrid.Offset(PLOT_BORDER, PLOT_BORDER); - -// m_h = m_rGrid.GetHeight(); -// m_w = m_rGrid.GetWidth(); - - dc.Clear(); - - // Draw a filled rectangle with aborder - wxBrush ltYellowBrush = wxBrush(LIGHT_YELLOW_COLOR); - dc.SetBrush(ltYellowBrush); -// dc.SetBrush(BLACK_COLOR); -// dc.SetPen(wxPen(BLACK_COLOR, 1)); - m_top = PLOT_BORDER; - m_left = PLOT_BORDER + XLEFT_OFFSET; - dc.DrawRectangle(m_left, m_top, m_rCtrl.GetWidth(), m_rCtrl.GetHeight()); - - drawGraticule(dc); -/* - Fl_Box::draw(); - fl_color(FL_BLACK); - fl_rectf(x(),y(),w(),h()); - fl_color(FL_GREEN); - fl_line_style(FL_SOLID); - - fl_push_clip(x(),y(),w(),h()); - //printf("%d %d\n", w(), h()); -*/ -/* - dc.SetBrush(*wxBLUE_BRUSH); - dc.SetPen(wxPen(YELLOW_COLOR, 2)); - dc.DrawRectangle(PLOT_BORDER, PLOT_BORDER, m_w, m_h); - - x_px_per_point = (float)m_w / FDMDV_NSPEC; - y_px_per_dB = (float)m_h / (MAX_DB - MIN_DB); - - - // plot spectrum - for(i = 0; i < FDMDV_NSPEC - 1; i++) - { -// mag1 = av_mag[i]; -// mag2 = av_mag[i+1]; - - x1 = m_x + i * x_px_per_point; - y1 = m_y + -mag1 * y_px_per_dB; - x2 = m_x + (i+1) * x_px_per_point; - y2 = m_y + -mag2 * y_px_per_dB; -// fl_line(x1,y1,x2,y2); - } - - // y axis graticule -// fl_line_style(FL_DOT); - for(i=MIN_DB; iRefresh(); } } diff --git a/fdmdv2/src/fdmdv2_plot_spectrum.h b/fdmdv2/src/fdmdv2_plot_spectrum.h index 957de7fa..8e40a793 100644 --- a/fdmdv2/src/fdmdv2_plot_spectrum.h +++ b/fdmdv2/src/fdmdv2_plot_spectrum.h @@ -36,13 +36,16 @@ class PlotSpectrum : public PlotPanel public: // PlotSpectrum(wxFrame* parent, int x, int y, int w, int h); PlotSpectrum(wxFrame* parent); - ~PlotSpectrum() {}; + ~PlotSpectrum(); +// bool m_newdata; + protected: void OnPaint(wxPaintEvent& event); void OnSize(wxSizeEvent& event); void OnShow(wxShowEvent& event); void drawGraticule(wxAutoBufferedPaintDC& dc); void draw(wxAutoBufferedPaintDC& dc); + void drawData(); //wxMemoryDC& pDC); DECLARE_EVENT_TABLE() }; diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.cpp b/fdmdv2/src/fdmdv2_plot_waterfall.cpp index 508d7493..d6b4487b 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall.cpp +++ b/fdmdv2/src/fdmdv2_plot_waterfall.cpp @@ -74,59 +74,32 @@ PlotWaterfall::PlotWaterfall(wxFrame* parent): PlotPanel(parent) } //---------------------------------------------------------------- -// ~PlotWaterfall() +// paintEvent() +// +// Called by the system of by wxWidgets when the panel needs +// to be redrawn. You can also trigger this call by calling +// Refresh()/Update(). //---------------------------------------------------------------- -PlotWaterfall::~PlotWaterfall() +void PlotWaterfall::OnPaint(wxPaintEvent & evt) { + wxAutoBufferedPaintDC pdc(this); + draw(pdc); } -/* //---------------------------------------------------------------- -// new_pixel_buf() +// OnShow() //---------------------------------------------------------------- -void PlotWaterfall::new_pixel_buf(int w, int h) -{ -// int i; - - m_prev_w = w; - m_prev_h = h; - -// wxMemoryDC m_memDC = new wxMemoryDC(); - - if(m_bmp->IsOk()) - { - delete m_bmp; - //m_Bufsz = h * w; +void PlotWaterfall::OnShow(wxShowEvent& event) +{ +} - //m_img = new wxImage(sz, pdata, alpha, false); - m_bmp = new wxBitmap(w, h, wxBITMAP_SCREEN_DEPTH); - //m_pBmp = m_bmp->GetBitmapData(); - } -// m_pixel_buf = new unsigned[buf_sz]; -// for(i = 0; i < buf_sz; i++) -// { -// m_pixel_buf[i] = 0; -// } -} - //---------------------------------------------------------------- -// handle() +// ~PlotWaterfall() //---------------------------------------------------------------- -int PlotWaterfall::handle(int event) -{ - // detect a left mouse down if inside the window - if ((event == FL_NO_EVENT) && (Fl::event_button() == 1)) - { - if ((Fl::event_x() > x()) && (Fl::event_x() < (x() + w())) && (Fl::event_y() > y()) && (Fl::event_y() < (y() + h()))) - { - // show zoomed spectrum window - zoomWaterfallWindow->show(); - } - } - return 0; -} -*/ - +PlotWaterfall::~PlotWaterfall() +{ +} + //---------------------------------------------------------------- // heatmap() // map val to a rgb colour @@ -163,17 +136,18 @@ unsigned PlotWaterfall::heatmap(float val, float min, float max) return (b << 16) + (g << 8) + r; } -#define DATA_LINE_WIDTH 25 - +#define PLOT_BOTTOM 0 +#define PLOT_TOP 1 + +//static long paint_count; + //---------------------------------------------------------------- // draw() //---------------------------------------------------------------- void PlotWaterfall::draw(wxAutoBufferedPaintDC& pDC) { - bool rc; wxMemoryDC m_mDC; - m_mDC.SelectObject(*m_bmp); -// m_mDC.SetMapMode(pDC.GetMapMode()); + m_mDC.SelectObject(*m_pBmp); m_rCtrl = GetClientRect(); m_rGrid = m_rCtrl; @@ -181,16 +155,15 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& pDC) m_rGrid.Offset(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER); pDC.Clear(); +// m_mDC.Clear(); m_rPlot = wxRect(PLOT_BORDER + XLEFT_OFFSET, PLOT_BORDER, m_rGrid.GetWidth(), m_rGrid.GetHeight()); -// m_rPlot = m_rPlot.Deflate(1, 1); if(m_firstPass) { m_firstPass = false; m_mDC.FloodFill(0, 0, VERY_LTGREY_COLOR); -// m_rPlot.Offset(1, 1); // Draw a filled rectangle with aborder - wxBrush ltGraphBkgBrush = wxBrush(LIGHT_RED_COLOR); + wxBrush ltGraphBkgBrush = wxBrush(LIGHT_BLUE_COLOR); m_mDC.SetBrush(ltGraphBkgBrush); m_mDC.SetPen(wxPen(BLACK_COLOR, 0)); m_mDC.DrawRectangle(m_rPlot); @@ -198,62 +171,59 @@ void PlotWaterfall::draw(wxAutoBufferedPaintDC& pDC) if(m_newdata) { m_newdata = false; -// m_rPlot = m_rPlot.Deflate(2, 2); -// m_rPlot.Offset(1, 1); - // plotPixelData(dc); #ifdef USE_TIMER int t = m_rPlot.GetTop(); int l = m_rPlot.GetLeft(); - int b = m_rPlot.GetBottom(); - int r = m_rPlot.GetRight(); int h = m_rPlot.GetHeight(); +// int b = m_rPlot.GetBottom(); int w = m_rPlot.GetWidth(); - - wxDateTime dt; - char buf[15]; - sprintf(buf, "%9X", (unsigned int)dt.GetTimeNow()); - wxPen pen; - pen.SetCap(wxCAP_BUTT); - pen.SetStyle(wxPENSTYLE_SOLID); - pen.SetWidth(1); - pen.SetColour(BLACK_COLOR); - m_mDC.SetPen(pen); - m_mDC.DrawText(buf, l + 100, h - 38); -// bool rc = pDC.StretchBlit(l, t + DATA_LINE_WIDTH, r, b , &m_mDC, l, t, r, b - DATA_LINE_WIDTH); -// bool rc = pDC.StretchBlit(l, t, w, h - DATA_LINE_WIDTH, &m_mDC, l, t + DATA_LINE_WIDTH, w, h - DATA_LINE_WIDTH); -// bool rc = pDC.StretchBlit(l, t, w, h, &m_mDC, l, t, w, h); int t2 = t + 1; int w2 = w - 1; - rc = m_mDC.StretchBlit(l, t2, w2, h - (DATA_LINE_WIDTH), &m_mDC, l, t2 + DATA_LINE_WIDTH, w2, h - DATA_LINE_WIDTH); - switch(m_line_color) - { - case 0: - pen.SetColour(RED_COLOR); - m_line_color = 1; - break; - - case 1: - pen.SetColour(YELLOW_COLOR); - m_line_color = 2; - break; + int ht = (h - DATA_LINE_HEIGHT); - case 2: - pen.SetColour(BLUE_COLOR); - m_line_color = 0; - break; - } - pen.SetWidth(DATA_LINE_WIDTH); - m_mDC.SetPen(pen); - m_mDC.DrawLine(l + 1, h - (DATA_LINE_WIDTH/2) + 1, r, h - (DATA_LINE_WIDTH/2) + 1); - rc = pDC.Blit(l, t, w, h, &m_mDC, l, t); + drawData(); // m_mDC, PLOT_BOTTOM); +// m_mDC.StretchBlit(l, t2, w2, ht, &m_mDC, l, t2 + DATA_LINE_HEIGHT, w2, ht - 2); + m_mDC.StretchBlit(l, t2, w2, ht, &m_mDC, l, t2 + DATA_LINE_HEIGHT, w2, ht - 2); +// pDC.Blit(l, t, w, h, &m_mDC, l, t); // Scroll Up from Bottom + pDC.StretchBlit(l, (h - t) + 4, w, (-h) + 4, &m_mDC, l, t, w, h); // Scroll Down from top #endif + drawGraticule(pDC); } - drawGraticule(pDC); m_mDC.SetBrush(wxNullBrush); m_mDC.SelectObject(wxNullBitmap); } +//------------------------------------------------------------------------- +// drawData() +//------------------------------------------------------------------------- +void PlotWaterfall::drawData() //wxMemoryDC& pDC) +{ + wxNativePixelData dPix = wxNativePixelData(*m_pBmp, m_rCtrl); + m_pPix = &dPix; + if(m_pPix == NULL) + { + return; + } + wxNativePixelData::Iterator p(*m_pPix); + + int w = m_rPlot.GetWidth(); + int h = m_rPlot.GetHeight(); + p.Offset(*m_pPix, XLEFT_OFFSET + 3, h - (DATA_LINE_HEIGHT - 2)); + for(int y = 0; y < DATA_LINE_HEIGHT; ++y) + { + wxNativePixelData::Iterator rowStart = p; + for(int x = 0; x < (w - 1); ++x, ++p) + { + p.Red() = m_pTopFrame->m_rxPa->m_av_mag[x]; + p.Green() = m_pTopFrame->m_rxPa->m_av_mag[x]; + p.Blue() = m_pTopFrame->m_rxPa->m_av_mag[x]; + } + p = rowStart; + p.OffsetY(*m_pPix, 1); + } +} + //------------------------------------------------------------------------- // drawGraticule() //------------------------------------------------------------------------- @@ -263,12 +233,10 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& pDC) char buf[15]; wxString s; - //wxBrush ltGraphBkgBrush = wxBrush(LIGHT_RED_COLOR); wxBrush ltGraphBkgBrush; ltGraphBkgBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT); pDC.SetBrush(ltGraphBkgBrush); pDC.SetPen(wxPen(BLACK_COLOR, 1)); -// pDC.DrawRectangle(m_rPlot); // Vertical gridlines pDC.SetPen(m_penShortDash); @@ -287,7 +255,7 @@ void PlotWaterfall::drawGraticule(wxAutoBufferedPaintDC& pDC) for(p = GRID_INCREMENT; p < (m_rGrid.GetWidth() - YBOTTOM_OFFSET); p += GRID_INCREMENT) { sprintf(buf, "%1.1f Hz",(double)(p / 10)); - pDC.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/2); + pDC.DrawText(buf, p - PLOT_BORDER + XLEFT_OFFSET, m_rGrid.GetHeight() + YBOTTOM_OFFSET/3); } // Label the Y-Axis for(p = (m_rGrid.GetHeight() - GRID_INCREMENT); p > PLOT_BORDER; p -= GRID_INCREMENT) @@ -335,7 +303,7 @@ void PlotWaterfall::plotPixelData(wxAutoBufferedPaintDC& dc) intensity_per_dB = (float)256 /(MAX_DB - MIN_DB); last_row = (unsigned int *)m_pBmp + dy *(dy_blocks - 1)* m_rCtrl.GetWidth(); - wxNativePixelData data(*m_bmp); + wxNativePixelData data(*m_pBmp); if(!data) { // ... raw access to bitmap data unavailable, do something else ... @@ -383,40 +351,3 @@ void PlotWaterfall::plotPixelData(wxAutoBufferedPaintDC& dc) } } } - -//---------------------------------------------------------------- -// paintEvent() -// -// 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 PlotWaterfall::OnPaint(wxPaintEvent & evt) -{ - wxAutoBufferedPaintDC pdc(this); - draw(pdc); -} - -//---------------------------------------------------------------- -// OnSize() -//---------------------------------------------------------------- -//void PlotWaterfall::OnSize(wxSizeEvent& event) -//{ -// m_rCtrlPrev = m_rCtrl; -// m_rCtrl = GetClientRect(); -// if(m_use_bitmap) -// { -// m_firstPass = true; -// m_bmp = new wxBitmap(m_rCtrl.GetWidth(), m_rCtrl.GetHeight(), wxBITMAP_SCREEN_DEPTH); -// this->Refresh(); -// } -//} - -//---------------------------------------------------------------- -// OnShow() -//---------------------------------------------------------------- -void PlotWaterfall::OnShow(wxShowEvent& event) -{ -// wxAutoBufferedPaintDC dc(this); -// draw(); -} diff --git a/fdmdv2/src/fdmdv2_plot_waterfall.h b/fdmdv2/src/fdmdv2_plot_waterfall.h index 86046c36..d3eaa67f 100644 --- a/fdmdv2/src/fdmdv2_plot_waterfall.h +++ b/fdmdv2/src/fdmdv2_plot_waterfall.h @@ -43,13 +43,12 @@ class PlotWaterfall : public PlotPanel public: PlotWaterfall(wxFrame* parent); ~PlotWaterfall(); +// bool m_newdata; protected: // unsigned *m_pixel_buf; unsigned m_heatmap_lut[256]; - int m_greyscale; wxMemoryDC m_mDC; - int m_line_color; unsigned heatmap(float val, float min, float max); @@ -59,6 +58,9 @@ class PlotWaterfall : public PlotPanel void drawGraticule(wxAutoBufferedPaintDC& dc); void draw(wxAutoBufferedPaintDC& pdc); void plotPixelData(wxAutoBufferedPaintDC& dc); + void drawData(); // wxMemoryDC& pDC); + void drawData2(wxMemoryDC& pDC, int barpos, int l, int t, int w, int h); + DECLARE_EVENT_TABLE() };