00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00015 #pragma implementation "drawing_canvas.h"
00016 #endif
00017
00018
00019 #include "wx/wxprec.h"
00020
00021 #ifdef __BORLANDC__
00022 #pragma hdrstop
00023 #endif
00024
00025 #ifndef WX_PRECOMP
00026 #include "wx/wx.h"
00027 #endif
00028 #include <wx/dcbuffer.h>
00029
00032
00033 #include "drawing_canvas.h"
00034 #include "drawing_panel.h"
00035
00037
00039
00044 IMPLEMENT_DYNAMIC_CLASS( DrawingCanvas, wxPanel )
00045
00046
00050 BEGIN_EVENT_TABLE( DrawingCanvas, wxPanel )
00051
00053 EVT_SIZE( DrawingCanvas::OnSize )
00054 EVT_PAINT( DrawingCanvas::OnPaint )
00055 EVT_ERASE_BACKGROUND( DrawingCanvas::OnEraseBackground )
00056
00058
00059 END_EVENT_TABLE()
00060
00065 DrawingCanvas::DrawingCanvas( ): m_parent( NULL), m_first_time(true), m_scope_index( 0)
00066 {
00067 this->m_p_back_bitmap= new wxBitmap( 1, 1);
00068 this->m_p_buffer_bitmap= new wxBitmap( 1, 1);
00069 }
00070
00071 DrawingCanvas::DrawingCanvas( int scope_index, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ): m_parent( (DrawingPanel*)parent), m_first_time(true)
00072 {
00073 this->m_scope_index= scope_index;
00074 this->m_p_back_bitmap= new wxBitmap( 1, 1);
00075 this->m_p_buffer_bitmap= new wxBitmap( 1, 1);
00076 Create(parent, id, pos, size, style);
00077 }
00078 DrawingCanvas::~DrawingCanvas()
00079 {
00080 delete this->m_p_back_bitmap;
00081 delete this->m_p_buffer_bitmap;
00082 }
00083
00088 bool DrawingCanvas::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00089 {
00092
00094 wxPanel::Create( parent, id, pos, size, style );
00095
00096 CreateControls();
00097 Centre();
00099 return true;
00100 }
00101
00106 void DrawingCanvas::CreateControls()
00107 {
00109
00110
00111 DrawingCanvas* itemPanel1 = this;
00112
00114 }
00115
00120 void DrawingCanvas::OnSize( wxSizeEvent& event )
00121 {
00122 this->RefreshBackBitmap();
00123 event.Skip();
00124 }
00125
00130 void DrawingCanvas::OnPaint( wxPaintEvent& event )
00131 {
00132 if( this->m_parent->IsFreezed())
00133 {
00134 event.Skip();
00135 return;
00136 }
00137
00138
00139 if( this->m_parent->m_app_settings== NULL)
00140 return;
00141
00142 if( this->m_first_time)
00143 {
00144 this->RefreshBackBitmap();
00145 this->m_first_time= false;
00146 }
00147
00148 wxBufferedPaintDC dc( this, *this->m_p_buffer_bitmap );
00149
00150 dc.DrawBitmap( *this->m_p_back_bitmap, 0, 0, false);
00151
00152 this->DrawSamples( dc);
00153 }
00154 void DrawingCanvas::DrawGrid( wxDC &dc)
00155 {
00156 wxMutexLocker lock( this->m_parent->m_app_settings->m_mutex);
00157
00158 if( this->m_parent->m_app_settings->m_grid_pen[ this->m_scope_index]== NULL)
00159 return;
00160 dc.SetPen( *this->m_parent->m_app_settings->m_grid_pen[ this->m_scope_index]);
00161
00162 int num_lines= NUM_DIV_PER_SCREEN;
00163 float step= (float)this->GetRect().width/ (float)num_lines;
00164 int i;
00165 for( i= 1; i< ( num_lines>> 1); i++)
00166 {
00167 dc.DrawLine( (int)((float)i* step), 0, (int)((float)i* step), this->GetRect().height);
00168 }
00169 for( i= ( num_lines>> 1)+ 1; i< num_lines; i++)
00170 {
00171 dc.DrawLine( (int)((float)i* step), 0, (int)((float)i* step), this->GetRect().height);
00172 }
00173
00174 step= (float)this->GetRect().height/ (float)num_lines;
00175
00176 for( i= 1; i< ( num_lines>> 1); i++)
00177 {
00178 dc.DrawLine( 0, (int)((float)i* step), this->GetRect().width, (int)((float)i* step));
00179 }
00180 for( i= ( num_lines>> 1)+ 1; i< num_lines; i++)
00181 {
00182 dc.DrawLine( 0, (int)((float)i* step), this->GetRect().width, (int)((float)i* step));
00183 }
00184 dc.SetPen( wxNullPen);
00185
00186 dc.SetPen( *this->m_parent->m_app_settings->m_mid_grid_pen[ this->m_scope_index]);
00187 i= ( num_lines>> 1);
00188 step= (float)this->GetRect().width/ (float)num_lines;
00189 dc.DrawLine( (int)((float)i* step), 0, (int)((float)i* step), this->GetRect().height);
00190 step= (float)this->GetRect().height/ (float)num_lines;
00191 dc.DrawLine( 0, (int)((float)i* step), this->GetRect().width, (int)((float)i* step));
00192
00193
00194 dc.SetPen( wxNullPen);
00195
00196 }
00197
00202 void DrawingCanvas::OnEraseBackground( wxEraseEvent& )
00203 {
00204 }
00205
00210 bool DrawingCanvas::ShowToolTips()
00211 {
00212 return true;
00213 }
00214
00219 wxBitmap DrawingCanvas::GetBitmapResource( const wxString& name )
00220 {
00221
00223 wxUnusedVar(name);
00224 return wxNullBitmap;
00226 }
00227
00232 wxIcon DrawingCanvas::GetIconResource( const wxString& name )
00233 {
00234
00236 wxUnusedVar(name);
00237 return wxNullIcon;
00239 }
00240 void DrawingCanvas::DrawTrigger( wxDC &dc)
00241 {
00242
00243
00244 for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00245 {
00246 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00247 board->DrawTrigger( this->m_scope_index, dc);
00248 }
00249 }
00250 void DrawingCanvas::DrawCursor( wxDC &dc)
00251 {
00252
00253
00254 for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00255 {
00256 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00257 board->DrawCursor( this->m_scope_index, dc);
00258 }
00259 }
00260
00261 void DrawingCanvas::DrawSamples( wxDC &dc)
00262 {
00263
00264
00265 for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00266 {
00267 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00268 board->DrawSamples( this->m_scope_index, dc);
00269 }
00270 }
00271 void DrawingCanvas:: RefreshBackBitmap( void)
00272 {
00273 if( this->m_parent->m_app_settings== NULL)
00274 return;
00275 if( this->m_parent->IsFreezed())
00276 {
00277 return;
00278 }
00279 if( ( this->m_pix_X!= this->GetRect().width)||( this->m_pix_Y!= this->GetRect().height))
00280 {
00281 this->m_pix_X= this->GetRect().width;
00282 this->m_pix_Y= this->GetRect().height;
00283
00284 for( size_t i= 0; i< this->m_parent->m_app_settings->m_board_array.GetCount(); i++)
00285 {
00286 GenericBoard *board= ( GenericBoard *)this->m_parent->m_app_settings->m_board_array[ i];
00287 board->SetDiv2Pix( this->m_scope_index, (double)this->m_pix_Y/ NUM_DIV_PER_SCREEN);
00288 board->SetPix( this->m_scope_index, this->m_pix_X, this->m_pix_Y);
00289 }
00290 this->m_parent->m_app_settings->SetDiv2Pix( this->m_scope_index, (double)this->m_pix_X/ NUM_DIV_PER_SCREEN);
00291 }
00292
00293 if(( this->m_p_back_bitmap->GetWidth()!= this->m_pix_X)||
00294 ( this->m_p_back_bitmap->GetHeight()!= this->m_pix_Y))
00295 {
00296 delete this->m_p_back_bitmap;
00297 this->m_p_back_bitmap= new wxBitmap( this->m_pix_X, this->m_pix_Y);
00298 delete this->m_p_buffer_bitmap;
00299 this->m_p_buffer_bitmap= new wxBitmap( this->m_pix_X, this->m_pix_Y);
00300 }
00301
00302 wxMemoryDC dc;
00303 dc.SelectObject( *this->m_p_back_bitmap);
00304
00305 this->DrawBackground( dc);
00306 this->DrawGrid( dc);
00307 this->DrawCursor( dc);
00308 this->DrawTrigger( dc);
00309 dc.SelectObject( wxNullBitmap);
00310
00311 }
00312 void DrawingCanvas::DrawBackground( wxDC &dc)
00313 {
00314 wxMutexLocker lock( this->m_parent->m_app_settings->m_mutex);
00315
00316 if( this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]== NULL)
00317 return;
00318 dc.SetBackground( *this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]);
00319 dc.Clear();
00320
00321 dc.SetBackground( *this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]);
00322 }