drawing_canvas.cpp

Go to the documentation of this file.
00001 
00002 // Name:        drawing_canvas.cpp
00003 // Purpose:     
00004 // Author:      NDA
00005 // Modified by: 
00006 // Created:     10/10/2006 15:08:09
00007 // RCS-ID:      
00008 // Copyright:   CAEN S.p.A All rights reserved.
00009 // Licence:     
00011 
00012 // Generated by DialogBlocks (unregistered), 10/10/2006 15:08:09
00013 
00014 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00015 #pragma implementation "drawing_canvas.h"
00016 #endif
00017 
00018 // For compilers that support precompilation, includes "wx/wx.h".
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     // Generated by DialogBlocks, 10/10/2006 15:08:09 (unregistered)
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         // wxMutexLocker lock( this->m_mutex);
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 /*, wxBUFFER_VIRTUAL_AREA*/);
00149         // Print samples directly
00150         dc.DrawBitmap( *this->m_p_back_bitmap, 0, 0, false);
00151         // draw directly to dc... wxBufferedPaintDC implementation provides buffer 
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         // vertical lines
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         // horizontal lines
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         // Middle lines
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         // Restore original pen
00194         dc.SetPen( wxNullPen);
00195         
00196 }
00197 
00202 void DrawingCanvas::OnEraseBackground( wxEraseEvent& /*event*/ )
00203 {
00204 }
00205 
00210 bool DrawingCanvas::ShowToolTips()
00211 {
00212     return true;
00213 }
00214 
00219 wxBitmap DrawingCanvas::GetBitmapResource( const wxString& name )
00220 {
00221     // Bitmap retrieval
00223     wxUnusedVar(name);
00224     return wxNullBitmap;
00226 }
00227 
00232 wxIcon DrawingCanvas::GetIconResource( const wxString& name )
00233 {
00234     // Icon retrieval
00236     wxUnusedVar(name);
00237     return wxNullIcon;
00239 }
00240 void DrawingCanvas::DrawTrigger( wxDC &dc)
00241 {
00242         //
00243         // Loop boards
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         // Loop boards
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         // Loop boards
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                 // Loop boards
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         // Restore original brush
00321         dc.SetBackground( *this->m_parent->m_app_settings->m_back_brush[ this->m_scope_index]);
00322 }

Generated on Mon Mar 19 17:14:07 2007 for CAENScope by  doxygen 1.4.6-NO